PHP code example of yannoff / console

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

    

yannoff / console example snippets


#!/usr/bin/env php

// bin/app.php

// Mute PHP deprecation warnings & notices
error_reporting(E_ERROR);

, '0.0.0');

$application->addCommands([
    new HelloCommand('hello'),
]);

$application->run();


// src/Acme/Demo/

namespace Acme\Demo;

use Yannoff\Component\Console\Command;
use Yannoff\Component\Console\Definition\Argument;
use Yannoff\Component\Console\Definition\Option;

class HelloCommand extends Command
{
    public function configure()
    {
        $this
            ->setName('hello')
            ->setHelp('Hello world')
            ->setDescription('Hello world demo application')
            ->addArgument(
                'name',
                Argument::OPTIONAL,
                'Optional name to greet'
            )
            ->addOption(
                'upper',
                'u',
                Option::FLAG,
                'Print the greetings in upper case'
            )
            ;
    }

    public function execute()
    {
        $name = $this->getArgument('name');
        $upper = $this->getOption('upper');

        $message = 'Hello ' . (null === $name ? 'World' : $name);
        if ($upper) {
            $message = strtoupper($message);
        }

        $this->write($message);

        return 0;
    }
}