1. Go to this page and download the library: Download andrewdyer/slim3-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/ */
andrewdyer / slim3-console example snippets
$app = new \Slim\App();
$kernel = new \Anddye\Console\Kernel\Kernel();
$kernel->addCommand(\Anddye\Console\Commands\SayHelloCommand::class);
$console = new \Anddye\Console\Console($app);
$console->boot($kernel);
$console->run();
$app = new \Slim\App();
$container = $app->getContainer();
$console = new \Anddye\Console\Console($app);
$console->add(new \Anddye\Console\Commands\SayHelloCommand($container));
$console->run();
namespace App\Commands;
use Anddye\Console\Commands\AbstractCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class SayHelloCommand extends AbstractCommand
{
/**
* Sets an array of argument to add to the command.
*
* @return array
*/
public function arguments(): array
{
return [
['name', InputArgument::REQUIRED, 'Your name.'],
];
}
/**
* Sets the description for the command.
*
* @return string
*/
public function description(): string
{
return 'Prints "Hello" and your name for a specific number of times.';
}
/**
* The body of the command.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return mixed
*/
public function handle(InputInterface $input, OutputInterface $output)
{
for ($i = 0; $i < $input->getOption('repeat'); ++$i) {
$this->info('Hello '.$input->getArgument('name'));
}
}
/**
* Sets the help for the command.
*
* @return string
*/
public function help(): string
{
return '';
}
/**
* Sets the name of the command.
*
* @return string
*/
public function name(): string
{
return 'say:hello';
}
/**
* Sets an array of options to add to the command.
*
* @return array
*/
public function options(): array
{
return [
['repeat', 'r', InputOption::VALUE_OPTIONAL, 'Times to repeat the output.', 1],
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.