PluginProbe
System Dashboard / 2.8.3
System Dashboard v2.8.3
trunk 1.0.0 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.4.0 1.5.1 1.5.2 1.6.0 1.7.1 1.7.2 1.8.0 1.9.0 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.1 All 62 releases
system-dashboard / vendor / phpdocumentor / reflection / src / phpDocumentor / Reflection / Traverser.php

Traverser.php in System Dashboard 2.8.3, at vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/Traverser.php

101 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * phpDocumentor
4 *
5 * PHP Version 5.3
6 *
7 * @author Mike van Riel <mike.vanriel@naenius.com>
8 * @copyright 2010-2012 Mike van Riel / Naenius (http://www.naenius.com)
9 * @license http://www.opensource.org/licenses/mit-license.php MIT
10 * @link http://phpdoc.org
11 */
12
13 namespace phpDocumentor\Reflection;
14
15 use PhpParser\Error;
16 use PhpParser\NodeVisitor\NameResolver;
17 use PhpParser\Parser;
18 use PhpParser\NodeTraverser;
19 use PhpParser\NodeVisitor;
20 use PhpParser\NodeVisitorAbstract;
21
22 /**
23 * The source code traverser that scans the given source code and transforms
24 * it into tokens.
25 *
26 * @author Mike van Riel <mike.vanriel@naenius.com>
27 * @license http://www.opensource.org/licenses/mit-license.php MIT
28 * @link http://phpdoc.org
29 */
30 class Traverser
31 {
32 /**
33 * List of visitors to apply upon traversing.
34 *
35 * @see traverse()
36 *
37 * @var \PhpParser\NodeVisitorAbstract[]
38 */
39 public $visitors = array();
40
41 /**
42 * Traverses the given contents and builds an AST.
43 *
44 * @param string $contents The source code of the file that is to be scanned
45 *
46 * @return void
47 */
48 public function traverse($contents)
49 {
50 try {
51 $this->createTraverser()->traverse(
52 $this->createParser()->parse($contents)
53 );
54 } catch (Error $e) {
55 echo 'Parse Error: ', $e->getMessage();
56 }
57 }
58
59 /**
60 * Adds a visitor object to the traversal process.
61 *
62 * With visitors it is possible to extend the traversal process and
63 * modify the found tokens.
64 *
65 * @param \PhpParser\NodeVisitor $visitor
66 *
67 * @return void
68 */
69 public function addVisitor(\PhpParser\NodeVisitor $visitor)
70 {
71 $this->visitors[] = $visitor;
72 }
73
74 /**
75 * Creates a parser object using our own Lexer.
76 *
77 * @return Parser
78 */
79 protected function createParser()
80 {
81 return new Parser(new Lexer());
82 }
83
84 /**
85 * Creates a new traverser object and adds visitors.
86 *
87 * @return NodeTraverser
88 */
89 protected function createTraverser()
90 {
91 $node_traverser = new NodeTraverser();
92 $node_traverser->addVisitor(new NameResolver());
93
94 foreach ($this->visitors as $visitor) {
95 $node_traverser->addVisitor($visitor);
96 }
97
98 return $node_traverser;
99 }
100 }
101