项目作者: tpunt

项目描述 :
Reverts the php-ast AST back into (somewhat) PSR-compliant code
高级语言: PHP
项目地址: git://github.com/tpunt/php-ast-reverter.git
创建时间: 2015-08-26T22:12:02Z
项目社区:https://github.com/tpunt/php-ast-reverter

开源协议:MIT License

下载


php-ast-reverter

A tool that reverts an abstract syntax tree (AST) produced by the
php-ast extension back into (somewhat)
PSR-compliant code. This enables for code preprocessing to be done.

Requirements:

  • PHP 7.*
  • php-ast extension (compatible with
    versions 30, 35, 40, 45, and 50)

Installation

Composer

  1. composer require tpunt/php-ast-reverter

Example

Running the following code snippet:

  1. <?php
  2. $code = <<<'end'
  3. <?php
  4. /**
  5. * My testing class
  6. */
  7. class ClassName extends AnotherClass implements AnInterface
  8. {
  9. /**
  10. * Some property
  11. */
  12. private $prop = 0;
  13. const TEST = 'string';
  14. use TraitA, TraitB {
  15. TraitA::func1 insteadof TraitB;
  16. TraitB::func1 as protected func2;
  17. }
  18. /**
  19. * Some useless constructor
  20. */
  21. function __construct(int $arg = 1)
  22. {
  23. $this->prop = $arg;
  24. }
  25. }
  26. end;
  27. $ast = ast\parse_code($code, $version=40);
  28. echo (new AstReverter\AstReverter)->getCode($ast);

Will output:

  1. <?php
  2. /**
  3. * My testing class
  4. */
  5. class ClassName extends AnotherClass implements AnInterface
  6. {
  7. /**
  8. * Some property
  9. */
  10. private $prop = 0;
  11. const TEST = "string";
  12. use TraitA, TraitB {
  13. TraitA::func1 insteadof TraitB;
  14. TraitB::func1 as protected func2;
  15. }
  16. /**
  17. * Some useless constructor
  18. */
  19. public function __construct(int $arg = 1)
  20. {
  21. $this->prop = $arg;
  22. }
  23. }