PHP code example of adrianfalleiro / slim-cli-runner

1. Go to this page and download the library: Download adrianfalleiro/slim-cli-runner 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/ */

    

adrianfalleiro / slim-cli-runner example snippets


$app->add(new adrianfalleiro\SlimCliRunner\CliRunner::class);

use Psr\Http\Message\ResponseInterface as Response;
use adrianfalleiro\SlimCliRunner\CliAction;

use Psr\Log\LoggerInterface;

class ExampleCliAction extends CliAction
{
    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    protected function action(): Response
    {
        $arg0 = $this->resolveArg(0);
        $this->logToConsole("arg 0 is {$arg0}");

        return $this->respond();
    }
}

return function (ContainerBuilder $containerBuilder) {
    // Global Settings Object
    $containerBuilder->addDefinitions([
        'settings' => [
            ...
        ],
        'commands' => [
            '__default' => \Namespace\To\Task::class
            'SampleTask' => \Namespace\To\Task::class
        ]
    ]);
};

php public/index.php SampleTask arg1 arg2 arg3
json
{
    /*...*/
    "config": {
        "process-timeout" : 0
    },
    "scripts": {
        /*...*/
        "cli": "php public/index.php"
    }
}