PHP code example of rougin / blueprint

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

    

rougin / blueprint example snippets

 php
// blueprint.php

$file = array();

// Details for the console app ---
$file['name'] = 'Blueprint';

$file['version'] = '0.7.1';
// -------------------------------

// Path for the commands and templates ----
$paths = array();

$root = '%%CURRENT_DIRECTORY%%';

$paths['templates'] = $root . '/Templates';

$paths['commands'] = $root . '/Commands';

$file['paths'] = $paths;
// ----------------------------------------

// Namespace for the commands ----------
$namespace = 'Acme\Commands';

$data = array('commands' => $namespace);

$file['namespaces'] = $data;
// -------------------------------------

return $file;
 diff
 // blueprint.php

 // ...

-$namespace = 'Acme\Commands';
+$namespace = 'Rrsg\Commands';
 php
// src/Commands/TestCommand.php

namespace Rrsg\Commands;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestCommand extends Command
{
    protected function configure()
    {
        $this->setName('test');

        $this->setDescription('Returns a "Test" string');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Test</info>');
    }
}
 php
// bin/app.php

use Rougin\Blueprint\Blueprint;

// Return the root from "vendor" --------
$vendor = __DIR__ . '/../../../../';

$default = __DIR__ . '/../';

$loader = '/vendor/autoload.php';

$exists = file_exists($vendor . $loader);

$root = $exists ? $vendor : $default;
// --------------------------------------

// Load the Composer autoloader -------
 php
// bin/app.php

// ...

// Sets the directory for the defined commands ----
$app->setCommandPath(__DIR__ . '/../src/Commands');
// ------------------------------------------------

// Sets the directory for the templates. Useful -----
// for creating commands with template engines ------
$app->setTemplatePath(__DIR__ . '/../src/Templates');
// --------------------------------------------------

// Sets the name of the console application ---
$app->setName('Rrsg');
// --------------------------------------------

// Sets the version of the console application ---
$app->setVersion('0.1.0');
// -----------------------------------------------

// Sets the namespace for the "commands" path ---
$namespace = 'Rrsg\Simplest\Commands';

$app->setCommandNamespace($namespace);
// ----------------------------------------------

// Runs the console application ---
$app->run();
// --------------------------------
 php
// src/Commands/TestCommand.php

namespace Rrsg\Commands;

use Rougin\Blueprint\Command;

class TestCommand extends Command
{
    protected $name = 'test';

    protected $description = 'Returns a "Test" string';

    public function execute()
    {
        $this->showPass('Test');
    }
}
 php
// src/Sample.php

namespace Rrsg;

class Sample
{
    protected $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }
}
 php
namespace Rrsg\Commands;

use Rrsg\Sample;
use Rougin\Blueprint\Command;

class TextCommand extends Command
{
    protected $name = 'text';

    protected $description = 'Shows a sample text';

    protected $sample;

    public function __construct(Sample $sample)
    {
        $this->sample = $sample;
    }

    public function run()
    {
        $this->showText('Hello, ' . $this->sample->getName() . '!');

        return self::RETURN_SUCCESS;
    }
}
 bash
$ php bin/app.php text

Hello, Blueprint!