PHP code example of roolith / generator

1. Go to this page and download the library: Download roolith/generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

roolith / generator example snippets



use Roolith\Generator\GeneratorFactory;


$generator
    ->setTemplateDirectory(__DIR__.'/template') // this is your template directory
    ->setProjectBaseDirectory(__DIR__) // this is project base directory
    ->watch($argv); // this $argv to get console arguments



use Roolith\Generator\Command;
use Roolith\Generator\Console;
use Roolith\Generator\FileGenerator;
use Roolith\Generator\FileParser;
use Roolith\Generator\Interfaces\CommandInterface;

class TestCommand implements CommandInterface
{
    public function register()
    {
        return [
            'name' => 'test',
            'alias' => [],
            'typeAlias' => [],
        ];
    }

    public function handle(Command $command, Console $console, FileParser $fileParser, FileGenerator $fileGenerator)
    {
        $console->output('Test command registered!');
    }
}

$generator
    ->setTemplateDirectory(__DIR__.'/template')
    ->setProjectBaseDirectory(__DIR__)
    ->registerCommandClass([
        TestCommand::class
    ])
    ->watch($argv);
text
# outputBaseDir: Controllers

namespace Something;

class {{name}} extends Controller
{
    public function index()
    {
    }

    public function create()
    {
    }
}

shell script
php index.php generate controller DemoController
shell script
php index.php generate test something
shell script
php index.php test