Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getMatches(array $tokens, array $info = array())
 {
     $input = $this->getInput($tokens);
     return array_filter($this->commands, function ($command) use($input) {
         return AbstractMatcher::startsWith($input, $command);
     });
 }
Exemplo n.º 2
0
 /**
  * Handle readline completion.
  *
  * @param string $input Readline current word
  * @param int $index Current word index
  * @param array $info readline_info() data
  *
  * @return array
  */
 public function processCallback($input, $index, $info = array())
 {
     $line = substr($info['line_buffer'], 0, $info['end']);
     $tokens = token_get_all('<?php ' . $line);
     // remove whitespaces
     $tokens = array_filter($tokens, function ($token) {
         return !AbstractMatcher::tokenIs($token, AbstractMatcher::T_WHITESPACE);
     });
     $matches = array();
     foreach ($this->matchers as $matcher) {
         if ($matcher->hasMatched($tokens)) {
             $matches = array_merge($matcher->getMatches($tokens), $matches);
         }
     }
     $matches = array_unique($matches);
     return !empty($matches) ? $matches : array('');
 }
 /**
  * {@inheritdoc}
  */
 public function getMatches(array $tokens, array $info = array())
 {
     $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]);
     try {
         $object = $this->getVariable($objectName);
     } catch (InvalidArgumentException $e) {
         return array();
     }
     return array_filter(array_keys(get_class_vars(get_class($object))), function ($var) use($input) {
         return AbstractMatcher::startsWith($input, $var);
     });
 }