Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 200 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of Psy Shell.
5
 *
200 lars 6
 * (c) 2012-2023 Justin Hileman
148 lars 7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Psy\TabCompletion\Matcher;
13
 
14
/**
15
 * A PHP keyword tab completion Matcher.
16
 *
17
 * This matcher provides completion for all function-like PHP keywords.
18
 *
19
 * @author Marc Garcia <markcial@gmail.com>
20
 */
21
class KeywordsMatcher extends AbstractMatcher
22
{
23
    protected $keywords = [
24
        'array', 'clone', 'declare', 'die', 'echo', 'empty', 'eval', 'exit', 'include',
25
        'include_once', 'isset', 'list', 'print',  'require', 'require_once', 'unset',
26
    ];
27
 
28
    protected $mandatoryStartKeywords = [
29
        'die', 'echo', 'print', 'unset',
30
    ];
31
 
32
    /**
33
     * Get all (completable) PHP keywords.
34
     *
200 lars 35
     * @return string[]
148 lars 36
     */
37
    public function getKeywords(): array
38
    {
39
        return $this->keywords;
40
    }
41
 
42
    /**
43
     * Check whether $keyword is a (completable) PHP keyword.
44
     *
45
     * @param string $keyword
46
     */
47
    public function isKeyword(string $keyword): bool
48
    {
49
        return \in_array($keyword, $this->keywords);
50
    }
51
 
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getMatches(array $tokens, array $info = []): array
56
    {
57
        $input = $this->getInput($tokens);
58
 
59
        return \array_filter($this->keywords, function ($keyword) use ($input) {
60
            return AbstractMatcher::startsWith($input, $keyword);
61
        });
62
    }
63
 
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function hasMatched(array $tokens): bool
68
    {
69
        $token = \array_pop($tokens);
70
        $prevToken = \array_pop($tokens);
71
 
72
        switch (true) {
73
            case self::hasToken([self::T_OPEN_TAG, self::T_VARIABLE], $token):
74
//            case is_string($token) && $token === '$':
75
            case self::hasToken([self::T_OPEN_TAG, self::T_VARIABLE], $prevToken) &&
991 lars 76
            self::tokenIs($token, self::T_STRING):
148 lars 77
            case self::isOperator($token):
78
                return true;
79
        }
80
 
81
        return false;
82
    }
83
}