PHP code example of tsquare / scaffolding

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

    

tsquare / scaffolding example snippets




use Tsquare\FileGenerator\FileTemplate;
use Tsquare\FileGenerator\FileEditor;

/**
 * @var FileTemplate $template
 */


/**
 * Define the application root.
 */
$template->appBasePath(dirname(__DIR__, 1));


/**
 * Define the base path for the file.
 */
$template->destinationPath(dirname(__DIR__, 1) . '/Sample');


/**
 * Define the file name. If not defined, the name specified in the command will be used.
 */
$template->fileName('{name}Extension');


/**
 * Define the contents of the file.
 */
$template->fileContent(<<<'FILE'
namespace App\Foo\{name};

$foo = '{underscore}s';
$bar = '{dash}';

function foo{name}() {
    return true;
}

FILE);


/*
 * Editing actions can be added, that will be used if the file already exists.
 */
$editor = new FileEditor();

$editor->insertBefore('
function inserted{pascal}Function() {
    return true;
}

', 'function foo{name}()');

$editor->insertAfter('
function another{pascal}Function()  {
    return true;
}
', 'function foo{name}() {
        return true;
    }
');

$editor->replace('another{pascal}Function', 'someOther{pascal}Function');

$template->ifFileExists($editor);

#!/usr/bin/env php


App;

$command = new App('1.0.0', __DIR__ . '/template-config');
$command->run();