File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 66use phootwork \collection \Set ;
77use phootwork \file \exception \FileNotFoundException ;
88use phootwork \file \File ;
9- use PhpParser \Lexer \Emulative ;
109use PhpParser \Node ;
1110use PhpParser \NodeTraverser ;
1211use PhpParser \NodeVisitorAbstract ;
13- use PhpParser \Parser ;
1412
1513class FileParser extends NodeVisitorAbstract {
1614
@@ -47,12 +45,21 @@ public function parse() {
4745 throw new FileNotFoundException (sprintf ('File (%s) does not exist. ' , $ this ->filename ));
4846 }
4947
50- $ parser = new Parser ( new Emulative () );
48+ $ parser = $ this -> getParser ( );
5149 $ traverser = new NodeTraverser ();
5250 $ traverser ->addVisitor ($ this );
5351 $ traverser ->traverse ($ parser ->parse ($ file ->read ()));
5452 }
5553
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+
5663 public function enterNode (Node $ node ) {
5764 foreach ($ this ->visitors as $ visitor ) {
5865 switch ($ node ->getType ()) {
You can’t perform that action at this time.
0 commit comments