PHP code example of paulhenri-l / generator

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

    

paulhenri-l / generator example snippets


$generator = new \PaulhenriL\Generator\Generator();

$spec = new HelloWorld('Paul-Henri');

$generator->generate($spec);



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(),
        ];
    }
}