TheSeer\Autoload\Parser::parse PHP Метод

parse() публичный Метод

Parse a given file for defintions of classes, traits and interfaces
public parse ( TheSeer\Autoload\SourceFile $source ) : TheSeer\Autoload\ParseResult
$source TheSeer\Autoload\SourceFile file to process
Результат TheSeer\Autoload\ParseResult
    public function parse(SourceFile $source)
    {
        $this->found = array();
        $this->redeclarations = array();
        $this->inNamespace = '';
        $this->aliases = array();
        $this->bracketLevel = 0;
        $this->inUnit = '';
        $this->nsBracket = 0;
        $this->classBracket = 0;
        $this->tokenArray = $source->getTokens();
        $tokenCount = count($this->tokenArray);
        $tokList = array_keys($this->methodMap);
        for ($t = 0; $t < $tokenCount; $t++) {
            $current = (array) $this->tokenArray[$t];
            if ($current[0] == T_STRING && $current[1] == 'trait' && T_TRAIT == -1) {
                // PHP < 5.4 compat fix
                $current[0] = T_TRAIT_53;
                $this->tokenArray[$t] = $current;
            }
            if (!in_array($current[0], $tokList)) {
                continue;
            }
            // PHP 5.5 has classname::class, reusing T_CLASS
            if ($this->tokenArray[$t - 1][0] == T_DOUBLE_COLON) {
                continue;
            }
            $t = call_user_func(array($this, $this->methodMap[$current[0]]), $t);
        }
        return new ParseResult($this->found, $this->dependencies, $this->redeclarations);
    }

Usage Example

Пример #1
0
 public function testGroupUseSyntaxWithConstIsHandeled()
 {
     $parser = new Parser();
     $rc = $parser->parse(new SourceFile(__DIR__ . '/_data/parser/groupuse2.php'));
     $units = array('some\\name\\space\\classd');
     $dependencies = array('my\\other\\name\\interfaceb', 'some\\name\\space\\foo');
     $this->assertEquals($units, $rc->getUnits());
     $this->assertEquals($dependencies, $rc->getDependenciesForUnit('some\\name\\space\\classd'));
 }
All Usage Examples Of TheSeer\Autoload\Parser::parse