PHP code example of corneltek / genphp

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

    

corneltek / genphp example snippets


class Generator {

    public function brief() { return 'your generator brief'; }

    public function generate($argument1,$argument2) 
    {
        // do your operations here
        $this->copyDir('etc','etc');  
    }
}

$this->copyDir('from/path','to/path');  

$this->touch('path/to/touch');          

$this->create('path/to/file', 'file content' );         

$this->copy( 'path/file1' , 'file2' );

$this->createDir( 'path/to/directory' );

$this->render('templateName.php.twig','path/to/file', array(
    'className' => $className
));

$this->writeJson('file.json', array( 'name' => 'John' ) );  // executes WriteJsonOperation

$this->writeYaml('file.yaml', array( 'name' => 'John' ) );  // executes WriteJsonOperation

$this->gitClone( '[email protected]:.....git' , 'path/to/repo' );

$this->hgClone( 'hg uri' , 'path/to/repo' );

$path = $flavor->path( 'license' );


$loader = new \Flavor\FlavorLoader;
$flavor = $loader->load( $flavorName );
$generator = $flavor->getGenerator();
$generator->setLogger( $this->getLogger() );

$args = func_get_args();
array_shift($args);

$runner = new \GenPHP\GeneratorRunner;
$runner->logger = $logger;
$runner->run($generator,$args);

public fucntion generate($argument1,$argument2, ... ) 
{
    $file = $this->flavorLoader->load('license')->path('LICENSE.GPL2');
    $this->copy($file, 'LICENSE' );
    $this->copyDir( );
}

namespace flavor;
use GenPHP\Flavor\BaseGenerator;
use GenPHP\Path;

class Generator extends BaseGenerator
{
    public function brief() { 
        return "Default Flavor";
    }

    public function generate($name)
    {
        $paths = Path::get_flavor_paths();
        foreach( $paths as $path ) {
            if( file_exists($path) ) {
                $base = $path . DIRECTORY_SEPARATOR . $name;
                $this->createDir( $base . DIRECTORY_SEPARATOR . "Resource");
                $this->render( 'Generator.php.twig',  
                    $base . DIRECTORY_SEPARATOR . 'Generator.php', 
                    array( 'name' => $name ) );
            }
        }
        
    }
}

// executes CopyDirOperation
$this->copyDir('from/path','to/path');  

// executes TouchOperation
$this->touch('path/to/touch');          

// executes TouchOperation
$this->create('path/to/file', 'file content' );         

// executes RenderOperation
$this->render('templateName.php.twig','path/to/file', array(
    'className' => $className
));

// executes WriteJsonOperation
$this->writeJson('file.json', array( ... ) );  // executes WriteJsonOperation