当前位置: 首页>>代码示例>>PHP>>正文


PHP NodeTraverser::addVisitor方法代码示例

本文整理汇总了PHP中PhpParser\NodeTraverser::addVisitor方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeTraverser::addVisitor方法的具体用法?PHP NodeTraverser::addVisitor怎么用?PHP NodeTraverser::addVisitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhpParser\NodeTraverser的用法示例。


在下文中一共展示了NodeTraverser::addVisitor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     $this->traverser = new NodeTraverser();
     $this->visitor = new ClassVisitor();
     $this->traverser->addVisitor($this->visitor);
     $this->parser = new Parser(new Lexer());
 }
开发者ID:mfn,项目名称:cakephp2-magic-properties,代码行数:7,代码来源:ClassVisitorTest.php

示例2: setUp

 protected function setUp()
 {
     $this->parser = new \PhpParser\Parser(new \PhpParser\Lexer());
     $this->traverser = new \PhpParser\NodeTraverser();
     $this->sut = $this->createVisitor();
     $this->traverser->addVisitor($this->sut);
 }
开发者ID:trismegiste,项目名称:phpunit-assert-solid,代码行数:7,代码来源:VisitorTestCase.php

示例3: __construct

 /**
  * @param \PhpParser\Parser $parser
  * @param Compiler $compiler
  */
 public function __construct(\PhpParser\Parser $parser, Compiler $compiler)
 {
     $this->nodeTraverser = new \PhpParser\NodeTraverser();
     $this->nodeTraverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver());
     $this->parser = $parser;
     $this->compiler = $compiler;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:11,代码来源:FileParser.php

示例4: getTags

 /**
  * Parse a file and return found tags.
  *
  * @param string $filePath Full path to filename.
  * @return array
  */
 public function getTags($filePath)
 {
     // Create a PHP-Parser instance.
     $parser = new PhpParser(new Lexer(array('usedAttributes' => array('startLine', 'endLine', 'startFilePos', 'endFilePos'))));
     // Parse the source code into a list of statements.
     $source = $this->getContents($filePath);
     $statements = $parser->parse($source);
     $traverser = new NodeTraverser();
     // Make sure all names are resolved as fully qualified.
     $traverser->addVisitor(new NameResolver());
     // Create visitors that turn statements into tags.
     $visitors = array(new Visitor\ClassDefinition(), new Visitor\ClassReference(), new Visitor\ConstantDefinition(), new Visitor\FunctionDefinition(), new Visitor\GlobalVariableDefinition(), new Visitor\InterfaceDefinition(), new Visitor\TraitDefinition());
     foreach ($visitors as $visitor) {
         $traverser->addVisitor($visitor);
     }
     $traverser->traverse($statements);
     // Extract tags from the visitors.
     $tags = array();
     foreach ($visitors as $visitor) {
         $tags = array_merge($tags, array_map(function (Tag $tag) use($source) {
             $comment = substr($source, $tag->getStartFilePos(), $tag->getEndFilePos() - $tag->getStartFilePos() + 1);
             if (($bracePos = strpos($comment, '{')) !== false) {
                 $comment = substr($comment, 0, $bracePos) . ' {}';
             }
             return $tag->setComment(preg_replace('/\\s+/', ' ', $comment));
         }, $visitor->getTags()));
     }
     return $tags;
 }
开发者ID:jorissteyn,项目名称:phptags,代码行数:35,代码来源:Parser.php

示例5: __construct

 public function __construct(OutputInterface $output)
 {
     $this->parser = new Parser(new Lexer());
     $this->traverser = new NodeTraverser();
     $this->nodeVisitor = new PhpStringFinder($output);
     $this->traverser->addVisitor($this->nodeVisitor);
 }
开发者ID:clockworkgeek,项目名称:magei18n,代码行数:7,代码来源:PhpScanner.php

示例6: __construct

 /**
  * DefaultPhpFileExtractor constructor.
  * @param DocParser $docParser
  * @param FileSourceFactory $fileSourceFactory
  */
 public function __construct(DocParser $docParser, FileSourceFactory $fileSourceFactory)
 {
     $this->docParser = $docParser;
     $this->fileSourceFactory = $fileSourceFactory;
     $this->traverser = new NodeTraverser();
     $this->traverser->addVisitor($this);
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:12,代码来源:TranslatableExceptionsFileVisitor.php

示例7: lint

 /**
  * @param $code
  * @param bool $autoFix - In case of true - pretty code will be generated (avaiable by getPrettyCode method)
  * @return Logger
  */
 public function lint($code, $autoFix = false)
 {
     $this->autoFix = $autoFix;
     $this->prettyCode = '';
     $this->logger = new Logger();
     try {
         $stmts = $this->parser->parse($code);
     } catch (Error $e) {
         $this->logger->addRecord(new LogRecord('', '', Logger::LOGLEVEL_ERROR, $e->getMessage(), ''));
         return $this->logger;
     }
     $traverser = new NodeTraverser();
     $rulesVisitor = new RulesVisitor($this->rules, $this->autoFix);
     $traverser->addVisitor($rulesVisitor);
     $traverser->traverse($stmts);
     $messages = $rulesVisitor->getLog();
     foreach ($messages as $message) {
         $this->logger->addRecord(new LogRecord($message['line'], $message['column'], $message['level'], $message['message'], $message['name']));
     }
     if ($autoFix) {
         $prettyPrinter = new PrettyPrinter\Standard();
         $this->prettyCode = $prettyPrinter->prettyPrint($stmts);
     }
     $sideEffectVisitor = new SideEffectsVisitor();
     $traverser->addVisitor($sideEffectVisitor);
     $traverser->traverse($stmts);
     if ($sideEffectVisitor->isMixed()) {
         $this->logger->addRecord(new LogRecord('', '', Logger::LOGLEVEL_ERROR, 'A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side' . 'effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both.', ''));
     }
     return $this->logger;
 }
开发者ID:koktut,项目名称:hexlet-psr-linter,代码行数:36,代码来源:PsrLinter.php

示例8: __construct

 /**
  * @param Parser $parser
  * @param NodeTraverser $traverser
  * @param TombstoneVisitor $visitor
  */
 public function __construct(Parser $parser, NodeTraverser $traverser, TombstoneVisitor $visitor)
 {
     $this->parser = $parser;
     $this->visitor = $visitor;
     $this->traverser = $traverser;
     $this->traverser->addVisitor($visitor);
 }
开发者ID:scheb,项目名称:tombstone-analyzer,代码行数:12,代码来源:TombstoneExtractor.php

示例9: __construct

 /**
  * @param RuleCollection $rules
  * @param bool           $fix
  * @param book           $debug
  */
 public function __construct($rules, $fix = false, $debug = false)
 {
     $parserFactory = new ParserFactory();
     $this->parser = $parserFactory->create(ParserFactory::PREFER_PHP7);
     $this->traverser = new NodeTraverser();
     $this->linterVisitor = new LinterVisitor($rules, $fix, $debug);
     $this->traverser->addVisitor($this->linterVisitor);
 }
开发者ID:sadovnik,项目名称:hexlet-psr-linter,代码行数:13,代码来源:Linter.php

示例10: parsePhpFileFromStringAndTraverseWithVisitor

 protected function parsePhpFileFromStringAndTraverseWithVisitor(PhpFileInfo $phpFileInfo, $source, VisitorInterface $visitor)
 {
     $traverser = new NodeTraverser();
     $traverser->addVisitor(new NameResolver());
     $traverser->addVisitor($visitor->setPhpFileInfo($phpFileInfo));
     $parser = new Parser(new Emulative());
     $traverser->traverse($parser->parse($source));
     return $phpFileInfo;
 }
开发者ID:rnuernberg,项目名称:deprecation-detector,代码行数:9,代码来源:FindTestCase.php

示例11: analyze

 /**
  * Get the fullyqualified imports and typehints.
  *
  * @param string $path
  *
  * @return string[]
  */
 public function analyze($path)
 {
     $traverser = new NodeTraverser();
     $traverser->addVisitor(new NameResolver());
     $traverser->addVisitor($imports = new ImportVisitor());
     $traverser->addVisitor($names = new NameVisitor());
     $traverser->traverse($this->parser->parse(file_get_contents($path)));
     return array_unique(array_merge($imports->getImports(), $names->getNames()));
 }
开发者ID:AltThree,项目名称:TestBench,代码行数:16,代码来源:ReferenceAnalyzer.php

示例12: parse

 /**
  * @param string $code
  * @param int $lineNumber
  * @return Node
  */
 public function parse($code, $lineNumber)
 {
     $stmts = $this->parser->parse($code);
     $this->nodeVisitor->setLine($lineNumber);
     $this->nodeTraverser->addVisitor($this->nodeVisitor);
     $this->nodeTraverser->traverse($stmts);
     $node = $this->nodeVisitor->getNode();
     return $node;
 }
开发者ID:angrybender,项目名称:phpPM,代码行数:14,代码来源:ParserLine.php

示例13: __construct

 /**
  * ValidationExtractor constructor.
  * @param $metadataFactory
  */
 public function __construct($metadataFactory)
 {
     if (!($metadataFactory instanceof MetadataFactoryInterface || $metadataFactory instanceof LegacyMetadataFactoryInterface || $metadataFactory instanceof ClassMetadataFactoryInterface)) {
         throw new \InvalidArgumentException(sprintf('%s expects an instance of MetadataFactoryInterface or ClassMetadataFactoryInterface', get_class($this)));
     }
     $this->metadataFactory = $metadataFactory;
     $this->traverser = new NodeTraverser();
     $this->traverser->addVisitor($this);
 }
开发者ID:AntoineLemaire,项目名称:JMSTranslationBundle,代码行数:13,代码来源:ValidationExtractor.php

示例14: modified

 /**
  * Get the modified AST
  *
  * @param  string $view
  * @return array
  */
 protected function modified($view)
 {
     $ast = $this->parser->parse($view);
     $traverser = new NodeTraverser();
     $traverser->addVisitor(new Modifiers\RegisterDeviseTags($this->parser));
     $traverser->addVisitor(new Modifiers\AddPlaceHolderTags($this->parser));
     $traverser->addVisitor(new Modifiers\EchoDeviseMagic($this->parser));
     return $traverser->traverse($ast);
 }
开发者ID:devisephp,项目名称:cms,代码行数:15,代码来源:DeviseCompiler.php

示例15: __construct

 public function __construct()
 {
     $this->registry = new Registry();
     $this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
     $this->traverser = new NodeTraverser();
     $visitors = [new NameResolver(), new ClassVisitor($this->registry), new InterfaceVisitor($this->registry), new FunctionVisitor($this->registry), new TraitVisitor($this->registry)];
     foreach ($visitors as $visitor) {
         $this->traverser->addVisitor($visitor);
     }
 }
开发者ID:nochso,项目名称:php-semver-checker,代码行数:10,代码来源:Scanner.php


注:本文中的PhpParser\NodeTraverser::addVisitor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。