PHP Classes

File: examples/BasicHandler/cmd

Recommend this page to a friend!
  Classes of Andrey Postal   EasyCLI   examples/BasicHandler/cmd   Download  
File: examples/BasicHandler/cmd
Role: Example script
Content type: text/plain
Description: Example script
Class: EasyCLI
Create CLI applications using handler functions
Author: By
Last change:
Date: 4 months ago
Size: 1,033 bytes
 

Contents

Class file image Download
<?php
namespace Andrey\Cli\Examples\BasicHandler;

use
Exception;
use
InvalidArgumentException;

use
Andrey\Cli\Types\Command;
use
Andrey\Cli\Types\Context;

use
Andrey\Cli\App;


use
Andrey\Cli\Types\ConsoleLevel;

require
'./../../vendor/autoload.php';

try {
   
$app = new App(
       
appName: 'MyApp',
       
description: 'My app has a cool description',
       
cmd: 'php cmd',
       
params: [],
       
commands: [
            new
Command(
               
key: 'run',
               
description: 'This action will run soon',
               
service: [
                   
'handler' => static function(Context $context): void {
                       
App::console('It is so easy!!!');
                    },
                ],
            ),
        ],
    );
   
$app->run($argv);
} catch (
InvalidArgumentException $e) {
   
App::console($e->getMessage(), ConsoleLevel::ERROR);
} catch (
Exception $e) {
   
App::console($e->getMessage(), ConsoleLevel::ERROR);
   
App::console(print_r($e, true), ConsoleLevel::ERROR);
}