Wallogit.com
2017 © Pedro Peláez
Very simple PHP CLI for school projects.
To create a project, open your terminal and run the following command:, (*1)
composer create-project marcus-campos/simple-php-cli MyCliAppName
To build commands just run php run make: command <command_name>., (*2)
When you create your command, you will have access to the Util class. It will normally be available within your class scope, see how you use it:, (*3)
<?php
namespace App\Commands;
use Console\BaseCommand;
use Console\Contracts\ConsoleContract;
class ClassName extends BaseCommand implements ConsoleContract
{
public function execute()
{
//Get the argument in the first position
$argument = $this->util->args()['arguments'][0];
//Prints a line in the console
$this->util->output()->writeLn('Hello world!', 'green');
//Prints a line in the console containing the value passed in the parameter
$this->util->output()->writeLn('My param ' . $argument, 'green');
}
}
The Util class contains methods to help when creating your command, follow the list of some of them (click to know more)., (*4)
To register your command, simply access the Command class, located in the ... /console/Command.php file, add another item to the $commands array. Ex:, (*5)
private $commands = [
...
'new:command' => [
'action' => MyCommand::class.'@execute',
'params' => [
'param1',
'param2',
'param3',
...
],
'description' => 'My command description',
],
...
];
Ex2:, (*6)
Command without parameters, (*7)
private $commands = [
...
'sympla' => [
'action' => SymplaCommand::class.'@inspire',
'description' => 'Descrição do meu outro comando',
],
...
];
Note: The parameters registered in this array are only descriptive by the help function., (*8)
To execute a command simply type:, (*9)
php run <nome_do_comando>
Ex:, (*10)
php run help
If the command has any parameters, execute it as follows:, (*11)
php run <nome_do_comando> <parametro1> <parametro2>
Ex:, (*12)
php run make:command TestCommand
Marcus Campos - campos.v.marcus@gmail.com, (*13)