php-writer
Update PHP scripts from their AST by using php-parser for reading and php-unparser for generating back the php.
How does it works?
You must include the module to your script and feed to it a php file string.
var fs = ; // Load the writervar writer = ; // Read file contentvar contents = fs; // All the possible optionsvar options = writer: indent: true dontUseWhitespaces: false shortArray: true forceNamespaceBrackets: false parser: debug: false locations: false extractDoc: false suppressErrors: false lexer: all_tokens: false comment_tokens: false mode_eval: false asp_tags: false short_tags: false ast: withPositions: true ; // Init the writervar myPhpFile = contents options; // Print the file AST objectconsole;
Options
You can pass to the writer an options object to customize your writer instance:
- writer: The same options you would pass to php-unparser
- parser: The same options you would pass to php-parser
- ast: The same options you would pass to php-parser
If you want to learn more about AST you can read the definitions.
Examples
All the examples assume that you have already loaded the file like in the example.
Find a function and set its body value:
var myPhpFile = contents options;myPhpFile;
Find a class and set a property value:
var myPhpFile = contents options;myPhpFile;