X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FMongoClientMatcher.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FMongoClientMatcher.php;h=eb15f15c262cc4d6a604e230b2133dbeb12a9ce7;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/psy/psysh/src/TabCompletion/Matcher/MongoClientMatcher.php b/vendor/psy/psysh/src/TabCompletion/Matcher/MongoClientMatcher.php new file mode 100644 index 000000000..eb15f15c2 --- /dev/null +++ b/vendor/psy/psysh/src/TabCompletion/Matcher/MongoClientMatcher.php @@ -0,0 +1,71 @@ + + */ +class MongoClientMatcher 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); + $objectName = str_replace('$', '', $objectToken[1]); + $object = $this->getVariable($objectName); + + if (!$object instanceof \MongoClient) { + return []; + } + + $list = $object->listDBs(); + + return array_filter( + array_map(function ($info) { + return $info['name']; + }, $list['databases']), + function ($var) use ($input) { + return AbstractMatcher::startsWith($input, $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; + } +}