Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/Psy/TabCompletion/Matcher/ClassNamesMatcher.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2017 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Psy\TabCompletion\Matcher; | |
13 | |
14 /** | |
15 * A class name tab completion Matcher. | |
16 * | |
17 * This matcher provides completion for all declared classes. | |
18 * | |
19 * @author Marc Garcia <markcial@gmail.com> | |
20 */ | |
21 class ClassNamesMatcher extends AbstractMatcher | |
22 { | |
23 /** | |
24 * {@inheritdoc} | |
25 */ | |
26 public function getMatches(array $tokens, array $info = array()) | |
27 { | |
28 $class = $this->getNamespaceAndClass($tokens); | |
29 if (strlen($class) > 0 && $class[0] === '\\') { | |
30 $class = substr($class, 1, strlen($class)); | |
31 } | |
32 $quotedClass = preg_quote($class); | |
33 | |
34 return array_map( | |
35 function ($className) use ($class) { | |
36 // get the number of namespace separators | |
37 $nsPos = substr_count($class, '\\'); | |
38 $pieces = explode('\\', $className); | |
39 //$methods = Mirror::get($class); | |
40 return implode('\\', array_slice($pieces, $nsPos, count($pieces))); | |
41 }, | |
42 array_filter( | |
43 get_declared_classes(), | |
44 function ($className) use ($quotedClass) { | |
45 return AbstractMatcher::startsWith($quotedClass, $className); | |
46 } | |
47 ) | |
48 ); | |
49 } | |
50 | |
51 /** | |
52 * {@inheritdoc} | |
53 */ | |
54 public function hasMatched(array $tokens) | |
55 { | |
56 $token = array_pop($tokens); | |
57 $prevToken = array_pop($tokens); | |
58 | |
59 $blacklistedTokens = array( | |
60 self::T_INCLUDE, self::T_INCLUDE_ONCE, self::T_REQUIRE, self::T_REQUIRE_ONCE, | |
61 ); | |
62 | |
63 switch (true) { | |
64 case self::hasToken(array($blacklistedTokens), $token): | |
65 case self::hasToken(array($blacklistedTokens), $prevToken): | |
66 case is_string($token) && $token === '$': | |
67 return false; | |
68 case self::hasToken(array(self::T_NEW, self::T_OPEN_TAG, self::T_NS_SEPARATOR), $prevToken): | |
69 case self::hasToken(array(self::T_NEW, self::T_OPEN_TAG, self::T_NS_SEPARATOR), $token): | |
70 case self::hasToken(array(self::T_OPEN_TAG, self::T_VARIABLE), $token): | |
71 case self::isOperator($token): | |
72 return true; | |
73 } | |
74 | |
75 return false; | |
76 } | |
77 } |