phpactor/code-builder
最新稳定版本:0.4.3
Composer 安装命令:
composer require phpactor/code-builder
包简介
Generating and modifying source code
README 文档
README
This library can be used to generate or idempotently add classes, methods, properties, use statements, etc. to existing source code using prototypes.
A prototype is an object which defines structural code elements.
Usage
The library provides a source code prototype builder:
$builder = SourceBuilder::create() ->namespace('Animals'); ->use('Measurements\\Height'); ->class('Rabbits') ->extends('Leopridae') ->property('force') ->visibility('private') ->type('int') ->defaultValue(5) ->end() ->method('jump') ->parameters() ->parameter('how') ->default('high') ->type('Height') ->end(); ->end() ->end() ->end(); $sourcePrototype = $builder->build();
the above prototype can either be used to generate a new class:
$renderer = new TwigRenderer(); $renderer->render($sourcePrototype);
Or it can be applied to an existing source code, given the following:
<?php class Rabbits { }
When we do:
$updater = new TolerantUpdater(); $updater->apply($sourcePrototype, Code::fromString(file_get_contents('Rabbits.php')));
Then we get:
<?php namespace Animals; use Measurements\Height; class Rabbits extends Leopridae { private $force = 5; public function jump(Height $how = 'high') { } }
About this project
This library is part of the phpactor project.
Contributing
This package is open source and welcomes contributions! Feel free to open a pull request on this repository.
Support
- Create an issue on the main Phpactor repository.
- Join the
#phpactorchannel on the Slack Symfony Devs channel.
统计信息
- 总下载量: 62.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-01