jumilla/source-generator

PHP source code generator. Can be written using a method chain.

1.1.2 2017-01-26 23:00 UTC

This package is not auto-updated.

Last update: 2024-11-05 04:48:15 UTC


README

Build Status Quality Score Code Coverage Latest Stable Version Total Downloads Software License

日本語ドキュメント - Japanese

<?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