Mercurial > hg > isophonics-drupal-site
annotate vendor/psy/psysh/src/Psy/TabCompletion/Matcher/FunctionsMatcher.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 /* |
Chris@0 | 4 * This file is part of Psy Shell. |
Chris@0 | 5 * |
Chris@0 | 6 * (c) 2012-2017 Justin Hileman |
Chris@0 | 7 * |
Chris@0 | 8 * For the full copyright and license information, please view the LICENSE |
Chris@0 | 9 * file that was distributed with this source code. |
Chris@0 | 10 */ |
Chris@0 | 11 |
Chris@0 | 12 namespace Psy\TabCompletion\Matcher; |
Chris@0 | 13 |
Chris@0 | 14 /** |
Chris@0 | 15 * A function name tab completion Matcher. |
Chris@0 | 16 * |
Chris@0 | 17 * This matcher provides completion for all internal and user-defined functions. |
Chris@0 | 18 * |
Chris@0 | 19 * @author Marc Garcia <markcial@gmail.com> |
Chris@0 | 20 */ |
Chris@0 | 21 class FunctionsMatcher extends AbstractMatcher |
Chris@0 | 22 { |
Chris@0 | 23 /** |
Chris@0 | 24 * {@inheritdoc} |
Chris@0 | 25 */ |
Chris@0 | 26 public function getMatches(array $tokens, array $info = array()) |
Chris@0 | 27 { |
Chris@0 | 28 $func = $this->getInput($tokens); |
Chris@0 | 29 |
Chris@0 | 30 $functions = get_defined_functions(); |
Chris@0 | 31 $allFunctions = array_merge($functions['user'], $functions['internal']); |
Chris@0 | 32 |
Chris@0 | 33 return array_filter($allFunctions, function ($function) use ($func) { |
Chris@0 | 34 return AbstractMatcher::startsWith($func, $function); |
Chris@0 | 35 }); |
Chris@0 | 36 } |
Chris@0 | 37 |
Chris@0 | 38 /** |
Chris@0 | 39 * {@inheritdoc} |
Chris@0 | 40 */ |
Chris@0 | 41 public function hasMatched(array $tokens) |
Chris@0 | 42 { |
Chris@0 | 43 $token = array_pop($tokens); |
Chris@0 | 44 $prevToken = array_pop($tokens); |
Chris@0 | 45 |
Chris@0 | 46 switch (true) { |
Chris@0 | 47 case self::tokenIs($prevToken, self::T_NEW): |
Chris@0 | 48 return false; |
Chris@0 | 49 case self::hasToken(array(self::T_OPEN_TAG, self::T_STRING), $token): |
Chris@0 | 50 case self::isOperator($token): |
Chris@0 | 51 return true; |
Chris@0 | 52 } |
Chris@0 | 53 |
Chris@0 | 54 return false; |
Chris@0 | 55 } |
Chris@0 | 56 } |