tpunt / php-ast-reverter
将抽象语法树(AST)还原为(某种程度上)PSR兼容的代码
v2.0
2017-06-12 18:35 UTC
Requires
- php: >=7.0
- ext-ast: *
Requires (Dev)
- phpunit/phpunit: ^6
This package is not auto-updated.
Last update: 2024-09-28 18:00:08 UTC
README
一个工具,可以将由 php-ast 扩展生成的抽象语法树(AST)还原为(某种程度上)PSR兼容的代码。这使得可以进行代码预处理。
要求
- PHP 7.*
- php-ast 扩展(兼容版本 30, 35, 40, 45 和 50)
安装
Composer
composer require tpunt/php-ast-reverter
示例
运行以下代码片段
<?php $code = <<<'end' <?php /** * My testing class */ class ClassName extends AnotherClass implements AnInterface { /** * Some property */ private $prop = 0; const TEST = 'string'; use TraitA, TraitB { TraitA::func1 insteadof TraitB; TraitB::func1 as protected func2; } /** * Some useless constructor */ function __construct(int $arg = 1) { $this->prop = $arg; } } end; $ast = ast\parse_code($code, $version=40); echo (new AstReverter\AstReverter)->getCode($ast);
将输出
<?php /** * My testing class */ class ClassName extends AnotherClass implements AnInterface { /** * Some property */ private $prop = 0; const TEST = "string"; use TraitA, TraitB { TraitA::func1 insteadof TraitB; TraitB::func1 as protected func2; } /** * Some useless constructor */ public function __construct(int $arg = 1) { $this->prop = $arg; } }