2017 © Pedro Peláez
 

library slim-cli-runner

Run command line tasks for Slim PHP

image

adrianfalleiro/slim-cli-runner

Run command line tasks for Slim PHP

  • Sunday, November 19, 2017
  • by adrianfalleiro
  • Repository
  • 3 Watchers
  • 14 Stars
  • 4,147 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 4 Versions
  • 107 % Grown

The README.md

Slim CLI Runner

Create and run command line tasks for the Slim PHP micro-framework, (*1)

Installation

Installation, (*2)

composer require adrianfalleiro/slim-cli-runner ^3.1

For Slim 3 support install version 2.6 or lower, (*3)

Register Middleware, (*4)

Register the middleware in middleware.php, (*5)

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

Define, Register and run your tasks

Task definition, (*6)

Tasks are classes which extend CliAction and have a public command() method., (*7)

You can inject dependencies through the class constructor., (*8)

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();
    }
}

Tasks registration, (*9)

Add a new key in your settings.php definitions file called commands and list your tasks. To define a default task (For use when no command name is provided) add a new task with __default as key, (*10)

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

Run Tasks, (*11)

There are multiple ways of doing this:
Directly via command line:, (*12)

php public/index.php SampleTask arg1 arg2 arg3

Via composer:
composer.json, (*13)

{
    /*...*/
    "config": {
        "process-timeout" : 0
    },
    "scripts": {
        /*...*/
        "cli": "php public/index.php"
    }
}

The command, (*14)

composer cli SampleTask argument1 argument2 argument3

Examples

An example project can be found in the examples/ folder, (*15)

The Versions

19/11 2017

dev-master

9999999-dev

Run command line tasks for Slim PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adrian Falleiro

cli slim

19/11 2017

2.4

2.4.0.0

Run command line tasks for Slim PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adrian Falleiro

cli slim

15/08 2017

2.1

2.1.0.0

Run command line tasks for Slim PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adrian Falleiro

cli slim

22/12 2016

2.0

2.0.0.0

Run command line tasks for Slim PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adrian Falleiro

cli slim