PHP code example of symfony2admingenerator / twig-generator

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

    

symfony2admingenerator / twig-generator example snippets




namespace MyProject\Builder;

use TwigGenerator\Builder\BaseBuilder;

class MyBuilder extends BaseBuilder
{
}


{{ namespace is defined ? "namespace " ~ namespace ~ ";" : "" }}

class {{ className }} {{ extends is defined ? "extends " ~ extends : "" }}
{
{% block functions %}
{% endblock %}
}


// initialize the autoload
ite PSR-0 autoloader configured with TwigGenerator, Symfony and Twig

// initialize a builder
$builder = new MyProject\Builder\MyBuilder();
$builder->setOutputName('MyBuilder.php');

// add specific configuration for my builder
$builder->setVariable('className', 'MyBuilder');

// create a generator
$generator = new TwigGenerator\Builder\Generator();
$generator->setTemplateDirs(array(
	__DIR__.'/templates',
));

// allways regenerate classes even if they exist -> no cache
$generator->setMustOverwriteIfExists(true);

// set common variables
$generator->setVariables(array(
	'namespace' => 'MyProject\Generated',
));

// add the builder to the generator
$generator->addBuilder($builder);

// You can add other builders here

// Run generation for all builders
$generator->writeOnDisk(__DIR__.'/Generated');


namespace MyProject\Generated;

class MyBuilder
{
	public function tellMeHello()
	{
		echo "Hello world";
	}
}

{% extends "_base/common.php.twig" %}

{% block functions %}
	public function tellMeHello()
	{
		echo "Hello world";
	}
{% endblock %}