Mercurial > hg > isophonics-drupal-site
annotate vendor/psy/psysh/src/Psy/TabCompletion/Matcher/ConstantsMatcher.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 constant name tab completion Matcher. |
Chris@0 | 16 * |
Chris@0 | 17 * This matcher provides completion for all defined constants. |
Chris@0 | 18 * |
Chris@0 | 19 * @author Marc Garcia <markcial@gmail.com> |
Chris@0 | 20 */ |
Chris@0 | 21 class ConstantsMatcher 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 $const = $this->getInput($tokens); |
Chris@0 | 29 |
Chris@0 | 30 return array_filter(array_keys(get_defined_constants()), function ($constant) use ($const) { |
Chris@0 | 31 return AbstractMatcher::startsWith($const, $constant); |
Chris@0 | 32 }); |
Chris@0 | 33 } |
Chris@0 | 34 |
Chris@0 | 35 /** |
Chris@0 | 36 * {@inheritdoc} |
Chris@0 | 37 */ |
Chris@0 | 38 public function hasMatched(array $tokens) |
Chris@0 | 39 { |
Chris@0 | 40 $token = array_pop($tokens); |
Chris@0 | 41 $prevToken = array_pop($tokens); |
Chris@0 | 42 |
Chris@0 | 43 switch (true) { |
Chris@0 | 44 case self::tokenIs($prevToken, self::T_NEW): |
Chris@0 | 45 case self::tokenIs($prevToken, self::T_NS_SEPARATOR): |
Chris@0 | 46 return false; |
Chris@0 | 47 case self::hasToken(array(self::T_OPEN_TAG, self::T_STRING), $token): |
Chris@0 | 48 case self::isOperator($token): |
Chris@0 | 49 return true; |
Chris@0 | 50 } |
Chris@0 | 51 |
Chris@0 | 52 return false; |
Chris@0 | 53 } |
Chris@0 | 54 } |