X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FObjectMethodsMatcher.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FObjectMethodsMatcher.php;h=cc45b1d9e92d501cdc62138318ddcafb893cb31e;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/psy/psysh/src/TabCompletion/Matcher/ObjectMethodsMatcher.php b/vendor/psy/psysh/src/TabCompletion/Matcher/ObjectMethodsMatcher.php new file mode 100644 index 000000000..cc45b1d9e --- /dev/null +++ b/vendor/psy/psysh/src/TabCompletion/Matcher/ObjectMethodsMatcher.php @@ -0,0 +1,80 @@ + + */ +class ObjectMethodsMatcher extends AbstractContextAwareMatcher +{ + /** + * {@inheritdoc} + */ + public function getMatches(array $tokens, array $info = []) + { + $input = $this->getInput($tokens); + + $firstToken = array_pop($tokens); + if (self::tokenIs($firstToken, self::T_STRING)) { + // second token is the object operator + array_pop($tokens); + } + $objectToken = array_pop($tokens); + if (!is_array($objectToken)) { + return []; + } + $objectName = str_replace('$', '', $objectToken[1]); + + try { + $object = $this->getVariable($objectName); + } catch (InvalidArgumentException $e) { + return []; + } + + if (!is_object($object)) { + return []; + } + + return array_filter( + get_class_methods($object), + function ($var) use ($input) { + return AbstractMatcher::startsWith($input, $var) && + // also check that we do not suggest invoking a super method(__construct, __wakeup, …) + !AbstractMatcher::startsWith('__', $var); + } + ); + } + + /** + * {@inheritdoc} + */ + public function hasMatched(array $tokens) + { + $token = array_pop($tokens); + $prevToken = array_pop($tokens); + + switch (true) { + case self::tokenIs($token, self::T_OBJECT_OPERATOR): + case self::tokenIs($prevToken, self::T_OBJECT_OPERATOR): + return true; + } + + return false; + } +}