PHP code example of leprz / boilerplate-generator

1. Go to this page and download the library: Download leprz/boilerplate-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/ */

    

leprz / boilerplate-generator example snippets


use Leprz\Boilerplate\PathNode\Folder;
use Leprz\Boilerplate\PathNode\Php\PhpClass;
use Leprz\Boilerplate\PathNode\Php\PhpMethod;
use Leprz\Boilerplate\PathNode\Php\PhpParameter;
use Leprz\Boilerplate\PathNode\Php\PhpType;
use Leprz\Boilerplate\Configuration;
use Leprz\Boilerplate\Generator;

$generator = new Generator(
    new Configuration(
        'AppPrefix',
        'src/'
    )
);

$command = (new Folder('Command'))
    ->addFolder(new Folder('ExampleUseCase'))
    ->addPhpClass(new PhpClass('ExampleCommand'));

$handler = (new Folder('Command'))
    ->addFolder(new Folder('ExampleUseCase'))
    ->addPhpClass(new PhpClass('ExampleHandler'))
    ->addMethod(new PhpMethod('__invoke', 'public', PhpType::void(), [
        new PhpParameter('command', PhpType::object($command))
    ]));

$generator->generate($command);
$generator->generate($handler);



declare(strict_types=1);

namespace AppPrefix\Command\ExampleUseCase;

/**
 * @package AppPrefix\Command\ExampleUseCase
 */
class ExampleCommand
{
}



declare(strict_types=1);

namespace AppPrefix\Command\ExampleUseCase;

/**
 * @package AppPrefix\Command\ExampleUseCase
 */
class ExampleHandler
{
    /**
     * @param \AppPrefix\Command\ExampleUseCase\ExampleCommand
     */
    public function __invoke(ExampleCommand $command): void
    {
    }
}

use Leprz\Boilerplate\PathNode\BoundedContext;
use Leprz\Boilerplate\PathNode\Layer;
use Leprz\Boilerplate\PathNode\Folder;
use Leprz\Boilerplate\PathNode\Php\PhpClass;
use Leprz\Boilerplate\PathNode\Php\PhpInterface;
use Leprz\Boilerplate\PathNode\Php\PhpMethod;
use Leprz\Boilerplate\PathNode\Php\PhpParameter;
use Leprz\Boilerplate\PathNode\Php\PhpType;

$this->testClass1 = (new Folder('Sample'))
    ->addPhpClass(new PhpClass('TestClass1'));

$this->testInterface1 = (new Folder('Sample'))
    ->addPhpInterface(new PhpInterface('TestInterface1'));

$this->testInterface2 = (new Folder('Sample'))
    ->addPhpInterface(new PhpInterface('TestInterface2'))
    ->addMethod(new PhpMethod('test', 'public', PhpType::string()));

$this->testClass2 = (new BoundedContext('Domain'))
    ->addLayer(new Layer('Application'))
    ->addFolder(new Folder('Command'))
    ->addPhpClass(new PhpClass('TestClass2'))
    ->extends($this->testClass1)
    ->implements($this->testInterface1, $this->testInterface2)
    ->addMethod(new PhpMethod('doSomething', 'public', PhpType::void(), [
        new PhpParameter('testClass1', PhpType::object($this->testClass1)),
        new PhpParameter('test', PhpType::string())
    ]))
    ->addMethod(new PhpMethod('doSomethingElse', 'private', PhpType::object($this->testClass1)));