GrumPHP\Parser\Php\Factory\TraverserFactory::createForTaskContext PHP Method

createForTaskContext() public method

public createForTaskContext ( array $parserOptions, ParserContext $context ) : NodeTraverser
$parserOptions array
$context GrumPHP\Parser\Php\Context\ParserContext
return PhpParser\NodeTraverser
    public function createForTaskContext(array $parserOptions, ParserContext $context)
    {
        $this->configurator->registerOptions($parserOptions);
        $this->configurator->registerContext($context);
        $traverser = new NodeTraverser();
        $this->configurator->configure($traverser);
        return $traverser;
    }

Usage Example

コード例 #1
0
ファイル: PhpParser.php プロジェクト: phpro/grumphp
 /**
  * @param SplFileInfo $file
  *
  * @return ParseErrorsCollection
  */
 public function parse(SplFileInfo $file)
 {
     $errors = new ParseErrorsCollection();
     $context = new ParserContext($file, $errors);
     $parser = $this->parserFactory->createFromOptions($this->parserOptions);
     $traverser = $this->traverserFactory->createForTaskContext($this->parserOptions, $context);
     try {
         $code = $this->filesystem->readFromFileInfo($file);
         $stmts = $parser->parse($code);
         $traverser->traverse($stmts);
     } catch (Error $e) {
         $errors->add(PhpParserError::fromParseException($e, $file->getRealPath()));
     }
     return $errors;
 }
All Usage Examples Of GrumPHP\Parser\Php\Factory\TraverserFactory::createForTaskContext