PHP code example of zachleigh / artisanize

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

    

zachleigh / artisanize example snippets


use Artisanize\Command;

class MyCommand extends Command
{
    /**
     * The command signature.
     *
     * @var string
     */
    protected $signature = 'signature';

    /**
     * The command description.
     *
     * @var string
     */
    protected $description = 'Description.';

    /**
     * Handle the command.
     */
    protected function handle()
    {
        // Handle your command
    }
}

use Artisanize\Command;

class ExampleCommand extends Command
{
    /**
     * The command signature.
     *
     * @var string
     */
    protected $signature = 'namespace:name {argument} {--o|option=default}';

    /**
     * The command description.
     *
     * @var string
     */
    protected $description = 'Command decription.';

    /**
     * Handle the command.
     */
    protected function handle()
    {
        // handle the command
    }
}

protected $signature = 'namespace:name';

protected $signature = 'namespace:name {arg} {--option}'

protected $signature = 'namespace:name {arg?} {--option}'

protected $signature = 'namespace:name {arg=default} {--option}'

protected $signature = 'namespace:name {arg*} {--option}'

protected $signature = 'namespace:name {arg?*} {--option}'

protected $signature = 'namespace:name {arg=default : Argument description} {--option}'

protected $signature = 'namespace:name {argument} {--opt}'

protected $signature = 'namespace:name {argument} {--opt=}'

protected $signature = 'namespace:name {argument} {--opt=default}'

protected $signature = 'namespace:name {argument} {--o|opt}'

protected $signature = 'namespace:name {argument} {--opt=*}'

protected $signature = 'namespace:name {argument} {--o|opt : option description.}'

protected function handle()
{
    $arg = $this->argument('arg'); // passed value of arg

    $allArguments = $this->argument(); // array of all arguments
}

protected function handle()
{
    $opt = $this->option('opt'); // passed value of opt

    $allOptions = $this->option(); // array of all options
}

protected function handle()
{
    $argExists = $this->hasArgument('exists');  // true

    $optExists = $this->hasOption('doesntExist');  // false
}

if ($this->confirm('Do you wish to continue? ')) {
    // user answered true
}

$name = $this->ask('What is your name?', 'Nobody');

$password = $this->askPassword('Please type your password');

$car = $this->choose('What is your favourite car?', ['Ferrari', 'Lamborghini', 'Maserati'], 1);

$food = $this->anticipate('What is your favourite food?', ['Pizza', 'Pasta', 'Lasagna'], 'Mozzarella');

$colors = $this->choice('What are your favourite colors (defaults to blue and red)?', ['Blue', 'Red', 'Green'], '0,1');

protected function handle()
{
    $this->output->write('Message'); // plain text

    $this->output->writeInfo('Message');  // green text

    $this->output->writeError('Message');  // red text

    $this->output->writeComment('Message');  // yellow text
}

protected function handle()
{
    $output = $this->getOutputInterface(); // $output is instance of Symfony\Component\Console\Output\OutputInterface
}

php app.php namespace:name one two three

php app.php namespace:name argument --opt

php app.php namespace:name argument -o

php app.php namespace:name argument --opt=one --opt=two --opt=three