jumilla / source-generator
PHP source code generator. Can be written using a method chain.
Installs: 2 672
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.9
- league/flysystem: ^1.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0|~5.0
This package is not auto-updated.
Last update: 2024-11-05 04:48:15 UTC
README
<?php use Jumilla\Generators\FileGenerator; $generator = FileGenerator::make('outdir-path', 'stubdir-path'); # copy $generator->sourceFile('Controller.php'); # generate in directory $name = 'notification'; $generator->directory('Services', function ($generator) use ($name) { $generator->file(ucfirst($name).'Service.php')->template('Service.php'); });
API
blank file
$generator->file('Class1.php')->blank();
source file from string
$generator->file('Class1.php')->text('## read');
source file from stub
$generator->sourceFile('Class1.php');
source file from string (with arguments)
$generator->file('Class2.php')->text('<?php class {$class_name} {}', [ 'class_name' => 'Class2', ]);
source file from stub (with arguments)
$generator->templateFile('Class2.php');
json file
$generator->json('Class2.php')->json([ 'foo' => 'FOO', 'bar' => 'BaR', ]);
.gitkeep file
$generator->gitKeepFile();
PHP blank file
$generator->phpBlankFile('functions.php');
PHP config file
$generator->phpConfigFile('config.php', [ 'theme' => 'snow', 'database' => [ 'default' => 'mysql', ], ]);
PHP source file
$generator->phpSourceFile('Controller.php', 'class Controller {}', 'App\Http\Controllers');
get directory walker
$sub = $generator->directory('app/Views'); $sub->sourceFile('layout.twig'); // ...
directory walk in Closure
$generator->directory('app/Views', function ($generator) { $generator->sourceFile('layout.twig'); // ... });
sources in directory
$generator->sourceDirectory(app/Models');
templates in directory
$generator->templateDirectory('app/Controllers', [ '' ]);
keep directory (use .gitkeep)
$generator->keepDirectory('app/Services');
Author
古川 文生 / Fumio Furukawa (fumio@jumilla.me)
Licnese
MIT