Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/bin/php-parse @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
24 | 24 |
25 if (empty($files)) { | 25 if (empty($files)) { |
26 showHelp("Must specify at least one file."); | 26 showHelp("Must specify at least one file."); |
27 } | 27 } |
28 | 28 |
29 $lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array( | 29 $lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => [ |
30 'startLine', 'endLine', 'startFilePos', 'endFilePos', 'comments' | 30 'startLine', 'endLine', 'startFilePos', 'endFilePos', 'comments' |
31 ))); | 31 ]]); |
32 $parser = (new PhpParser\ParserFactory)->create( | 32 $parser = (new PhpParser\ParserFactory)->create( |
33 PhpParser\ParserFactory::PREFER_PHP7, | 33 PhpParser\ParserFactory::PREFER_PHP7, |
34 $lexer | 34 $lexer |
35 ); | 35 ); |
36 $dumper = new PhpParser\NodeDumper([ | 36 $dumper = new PhpParser\NodeDumper([ |
37 'dumpComments' => true, | 37 'dumpComments' => true, |
38 'dumpPositions' => $attributes['with-positions'], | 38 'dumpPositions' => $attributes['with-positions'], |
39 ]); | 39 ]); |
40 $prettyPrinter = new PhpParser\PrettyPrinter\Standard; | 40 $prettyPrinter = new PhpParser\PrettyPrinter\Standard; |
41 $serializer = new PhpParser\Serializer\XML; | |
42 | 41 |
43 $traverser = new PhpParser\NodeTraverser(); | 42 $traverser = new PhpParser\NodeTraverser(); |
44 $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver); | 43 $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver); |
45 | 44 |
46 foreach ($files as $file) { | 45 foreach ($files as $file) { |
80 echo "==> Node dump:\n"; | 79 echo "==> Node dump:\n"; |
81 echo $dumper->dump($stmts, $code), "\n"; | 80 echo $dumper->dump($stmts, $code), "\n"; |
82 } elseif ('pretty-print' === $operation) { | 81 } elseif ('pretty-print' === $operation) { |
83 echo "==> Pretty print:\n"; | 82 echo "==> Pretty print:\n"; |
84 echo $prettyPrinter->prettyPrintFile($stmts), "\n"; | 83 echo $prettyPrinter->prettyPrintFile($stmts), "\n"; |
85 } elseif ('serialize-xml' === $operation) { | 84 } elseif ('json-dump' === $operation) { |
86 echo "==> Serialized XML:\n"; | 85 echo "==> JSON dump:\n"; |
87 echo $serializer->serialize($stmts), "\n"; | 86 echo json_encode($stmts, JSON_PRETTY_PRINT), "\n"; |
88 } elseif ('var-dump' === $operation) { | 87 } elseif ('var-dump' === $operation) { |
89 echo "==> var_dump():\n"; | 88 echo "==> var_dump():\n"; |
90 var_dump($stmts); | 89 var_dump($stmts); |
91 } elseif ('resolve-names' === $operation) { | 90 } elseif ('resolve-names' === $operation) { |
92 echo "==> Resolved names.\n"; | 91 echo "==> Resolved names.\n"; |
114 | 113 |
115 Operations is a list of the following options (--dump by default): | 114 Operations is a list of the following options (--dump by default): |
116 | 115 |
117 -d, --dump Dump nodes using NodeDumper | 116 -d, --dump Dump nodes using NodeDumper |
118 -p, --pretty-print Pretty print file using PrettyPrinter\Standard | 117 -p, --pretty-print Pretty print file using PrettyPrinter\Standard |
119 --serialize-xml Serialize nodes using Serializer\XML | 118 -j, --json-dump Print json_encode() result |
120 --var-dump var_dump() nodes (for exact structure) | 119 --var-dump var_dump() nodes (for exact structure) |
121 -N, --resolve-names Resolve names using NodeVisitor\NameResolver | 120 -N, --resolve-names Resolve names using NodeVisitor\NameResolver |
122 -c, --with-column-info Show column-numbers for errors (if available) | 121 -c, --with-column-info Show column-numbers for errors (if available) |
123 -P, --with-positions Show positions in node dumps | 122 -P, --with-positions Show positions in node dumps |
124 -r, --with-recovery Use parsing with error recovery | 123 -r, --with-recovery Use parsing with error recovery |
133 OUTPUT | 132 OUTPUT |
134 ); | 133 ); |
135 } | 134 } |
136 | 135 |
137 function parseArgs($args) { | 136 function parseArgs($args) { |
138 $operations = array(); | 137 $operations = []; |
139 $files = array(); | 138 $files = []; |
140 $attributes = array( | 139 $attributes = [ |
141 'with-column-info' => false, | 140 'with-column-info' => false, |
142 'with-positions' => false, | 141 'with-positions' => false, |
143 'with-recovery' => false, | 142 'with-recovery' => false, |
144 ); | 143 ]; |
145 | 144 |
146 array_shift($args); | 145 array_shift($args); |
147 $parseOptions = true; | 146 $parseOptions = true; |
148 foreach ($args as $arg) { | 147 foreach ($args as $arg) { |
149 if (!$parseOptions) { | 148 if (!$parseOptions) { |
158 break; | 157 break; |
159 case '--pretty-print': | 158 case '--pretty-print': |
160 case '-p': | 159 case '-p': |
161 $operations[] = 'pretty-print'; | 160 $operations[] = 'pretty-print'; |
162 break; | 161 break; |
163 case '--serialize-xml': | 162 case '--json-dump': |
164 $operations[] = 'serialize-xml'; | 163 case '-j': |
164 $operations[] = 'json-dump'; | |
165 break; | 165 break; |
166 case '--var-dump': | 166 case '--var-dump': |
167 $operations[] = 'var-dump'; | 167 $operations[] = 'var-dump'; |
168 break; | 168 break; |
169 case '--resolve-names': | 169 case '--resolve-names': |
196 $files[] = $arg; | 196 $files[] = $arg; |
197 } | 197 } |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 return array($operations, $files, $attributes); | 201 return [$operations, $files, $attributes]; |
202 } | 202 } |