X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FConstantsMatcher.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FConstantsMatcher.php;h=ddd8bcb0c48e73f3d6dbb796459f507537fbb860;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/psy/psysh/src/TabCompletion/Matcher/ConstantsMatcher.php b/vendor/psy/psysh/src/TabCompletion/Matcher/ConstantsMatcher.php new file mode 100644 index 000000000..ddd8bcb0c --- /dev/null +++ b/vendor/psy/psysh/src/TabCompletion/Matcher/ConstantsMatcher.php @@ -0,0 +1,54 @@ + + */ +class ConstantsMatcher extends AbstractMatcher +{ + /** + * {@inheritdoc} + */ + public function getMatches(array $tokens, array $info = []) + { + $const = $this->getInput($tokens); + + return array_filter(array_keys(get_defined_constants()), function ($constant) use ($const) { + return AbstractMatcher::startsWith($const, $constant); + }); + } + + /** + * {@inheritdoc} + */ + public function hasMatched(array $tokens) + { + $token = array_pop($tokens); + $prevToken = array_pop($tokens); + + switch (true) { + case self::tokenIs($prevToken, self::T_NEW): + case self::tokenIs($prevToken, self::T_NS_SEPARATOR): + return false; + case self::hasToken([self::T_OPEN_TAG, self::T_STRING], $token): + case self::isOperator($token): + return true; + } + + return false; + } +}