File tree 1 file changed +10
-3
lines changed 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 6
6
use phootwork \collection \Set ;
7
7
use phootwork \file \exception \FileNotFoundException ;
8
8
use phootwork \file \File ;
9
- use PhpParser \Lexer \Emulative ;
10
9
use PhpParser \Node ;
11
10
use PhpParser \NodeTraverser ;
12
11
use PhpParser \NodeVisitorAbstract ;
13
- use PhpParser \Parser ;
14
12
15
13
class FileParser extends NodeVisitorAbstract {
16
14
@@ -47,12 +45,21 @@ public function parse() {
47
45
throw new FileNotFoundException (sprintf ('File (%s) does not exist. ' , $ this ->filename ));
48
46
}
49
47
50
- $ parser = new Parser ( new Emulative () );
48
+ $ parser = $ this -> getParser ( );
51
49
$ traverser = new NodeTraverser ();
52
50
$ traverser ->addVisitor ($ this );
53
51
$ traverser ->traverse ($ parser ->parse ($ file ->read ()));
54
52
}
55
53
54
+ private function getParser () {
55
+ if (class_exists ('\\PhpParser \\ParserFactory ' )) {
56
+ $ factory = new \PhpParser \ParserFactory ();
57
+ return $ factory ->create (\PhpParser \ParserFactory::PREFER_PHP7 );
58
+ } else {
59
+ return new \PhpParser \Parser (new \PhpParser \Lexer \Emulative ());
60
+ }
61
+ }
62
+
56
63
public function enterNode (Node $ node ) {
57
64
foreach ($ this ->visitors as $ visitor ) {
58
65
switch ($ node ->getType ()) {
You can’t perform that action at this time.
0 commit comments