paulhenri-l/generator
Composer 安装命令:
composer require paulhenri-l/generator
包简介
Generate files from their specification
README 文档
README
Generate files from a specification. This tool is useful in scaffold commands.
Installation
You just need to require the package.
composer require paulhenri-l/generator
Usage
Generator use specifications to generate new files. A specification is a class
that implements the PaulhenriL\Generator\GeneratorSpecification interface.
You then pass this specification to the generate method of the Generator
$generator = new \PaulhenriL\Generator\Generator(); $spec = new HelloWorld('Paul-Henri'); $generator->generate($spec);
Defining a specification
Here's a sample specification.
<?php use PaulhenriL\Generator\GeneratorSpecification; class HelloWorld implements GeneratorSpecification { /** * The Name to greet. * * @var string */ protected $name; /** * HelloWorld constructor. */ public function __construct(string $name) { $this->name = $name; } /** * The template to use for generation. */ public function getTemplate(): string { // You may also store the template in another file and return it here // return file_get_contents('path/to/template'); return "<h1>{{ name }}</h1>"; } /** * Return the target path for the generated file. */ public function getTargetPath(): string { return getcwd() . '/welcome.html'; } /** * Return the replacements */ public function getReplacements(): array { return [ 'name' => $this->name ]; } /** * Return template processors. */ public function getProcessors(): array { return [ // Processors are callable that can process the file right before it // gets written to disk. Invokable classes are a good fit for this. // // new MyCustomProcessor(), ]; } }
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-21