showHelp("Must specify at least one file.");
}
-$lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array(
+$lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => [
'startLine', 'endLine', 'startFilePos', 'endFilePos', 'comments'
-)));
+]]);
$parser = (new PhpParser\ParserFactory)->create(
PhpParser\ParserFactory::PREFER_PHP7,
$lexer
'dumpPositions' => $attributes['with-positions'],
]);
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
-$serializer = new PhpParser\Serializer\XML;
$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
} elseif ('pretty-print' === $operation) {
echo "==> Pretty print:\n";
echo $prettyPrinter->prettyPrintFile($stmts), "\n";
- } elseif ('serialize-xml' === $operation) {
- echo "==> Serialized XML:\n";
- echo $serializer->serialize($stmts), "\n";
+ } elseif ('json-dump' === $operation) {
+ echo "==> JSON dump:\n";
+ echo json_encode($stmts, JSON_PRETTY_PRINT), "\n";
} elseif ('var-dump' === $operation) {
echo "==> var_dump():\n";
var_dump($stmts);
-d, --dump Dump nodes using NodeDumper
-p, --pretty-print Pretty print file using PrettyPrinter\Standard
- --serialize-xml Serialize nodes using Serializer\XML
+ -j, --json-dump Print json_encode() result
--var-dump var_dump() nodes (for exact structure)
-N, --resolve-names Resolve names using NodeVisitor\NameResolver
-c, --with-column-info Show column-numbers for errors (if available)
}
function parseArgs($args) {
- $operations = array();
- $files = array();
- $attributes = array(
+ $operations = [];
+ $files = [];
+ $attributes = [
'with-column-info' => false,
'with-positions' => false,
'with-recovery' => false,
- );
+ ];
array_shift($args);
$parseOptions = true;
case '-p':
$operations[] = 'pretty-print';
break;
- case '--serialize-xml':
- $operations[] = 'serialize-xml';
+ case '--json-dump':
+ case '-j':
+ $operations[] = 'json-dump';
break;
case '--var-dump':
$operations[] = 'var-dump';
}
}
- return array($operations, $files, $attributes);
+ return [$operations, $files, $attributes];
}