1. Go to this page and download the library: Download district5/cli 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/ */
district5 / cli example snippets
use District5\Cli\CliApp;
// Map any injectables that you want to pass
$injectables = [
'config' => [
// Put any configuration here.
]
];
// Start CliApp
$cliApp = CliApp::createApp($argv, $injectables); // or `$command = new CliApp($argv, $injectables);`
// Optionally, to support PSR-4 namespaces you can set a namespace prefix:
// $cliApp->setPsrNamespacePrefix('FooBar');
// By default, routes appended with 'Route' will be looked for. You can change this to be something else:
// $cliApp->setClassAppend('Command'); // would look for a class called 'XxxxxCommand'
// Run CliApp
$cliApp->run();
namespace MyApp;
use District5\Cli\CliCommand;
/**
* Class ExampleOneRoute
*/
class ExampleOneRoute extends CliCommand
{
public function run()
{
$this->outputInfo('Running Example One');
$this->outputInfo('--------');
$this->outputInfo('Single line');
$this->outputInfo(array('This', 'is', 'an', 'array'));
$this->outputError('Single error line!');
$this->outputError(array('This', 'is', 'also', 'an', 'array'));
$this->outputInfo('--------');
if ($this->getArgument(0) !== null) {
$this->outputInfo('You sent in: ' . $this->getArgument(0));
}
}
}