PHP code example of angrybytes / filegen

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

    

angrybytes / filegen example snippets


use Naneau\FileGen\Structure;
use Naneau\FileGen\Generator;

// Specify a structure to be generated
$structure = new Structure;
$structure
    ->directory('foo')
    ->file('bar/baz', 'these are the file contents');
    ->link('/some/file/somewhere', 'qux');

// Generate the structure
$generator = new Generator('/output/directory');
$generator->generate($structure);

use Naneau\FileGen\Structure;
use Naneau\FileGen\File\Contents\Copy;

$structure = new Structure;
$structure->file('foo', new Copy('/from/this/file'));

use Naneau\FileGen\Structure;
use Naneau\FileGen\File\Contents\Twig;

// $twig = ...

// Load a template
$template = $twig->load('some_template.twig');

// Parameters for the template
$parameters = array('foo' => 'bar')

$structure = new Structure;
$structure->file('foo', new Twig($template, $parameters));

use Naneau\FileGen\Generator;
use Naneau\FileGen\Structure;
use Naneau\FileGen\File\Contents\Twig;

// $twig = ...
$template = ;
$structure = new Structure;
$structure
    // A parameter "foo" is expected
    ->param('foo')

    // A bar parameter with a description
    ->param('bar', 'Please specify "bar"')

    // Can use {{ foo }} and {{ bar }}
    ->file('someFile', new Twig($twig->load('someFile.twig'));

    // Can also use {{ foo }} and {{ bar }}
    ->file('anotherFile', new Twig($twig->load('anotherFile.twig'));

// Set a default value for foo
$structure->getParameterDefinition()->get('foo')->setDefaultValue('Foo!');

// Pass values for the structure's parameters to the generator
$generator = new Generator('/output/directory', array(
    'foo' => 'foo!'
    'bar' => 12345
));

// Generate the structure
$generator->generate($structure);

use Naneau\FileGen\Console\Helper\ParameterHelper;

// $application = ...
$application->getHelperSet()->set(new ParameterHelper, 'filegenParameters');

protected function execute(InputInterface $input, OutputInterface $output)
{
    // $structure = ...

    $helper = $this->getHelper('filegenParameters');

    // Ask for all parameters one by one
    $parameters = $helper->askParameters($structure, $input, $output);

    // Ask for a single parameter
    $fooParameter = $structure->getParameterDefinition()->get('foo');
    $fooValue = $helper->askParameter($fooParameter, $input, $output);
}