1. Go to this page and download the library: Download asika/simple-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/ */
asika / simple-console example snippets
php
#!/bin/sh php
// Include single file
endor/autolod.php';
$app = new \Asika\SimpleConsole\Console;
// Use closure
$app->execute(function (\Asika\SimpleConsole\Console $app)
{
// PHP 5.3
$app->out('Hello');
// PHP 5.4 or higher use $this
$this->out('Hello');
// Return TRUE will auto convert to 0 exitcode.
return true;
});
php
class Build extends \Asika\SimpleConsole\Console
{
protected $help = <<<HELP
[Usage] php build.php <version>
[Options]
h | help Show help information
v Show more debug information.
HELP;
protected function doExecute ()
{
$this->out('Hello');
// Return TRUE will auto convert to 0 exitcode.
return true;
}
}
$app = new Build;
$app->execute();
php
$arg = $this->getArgument(0);
if (!$arg)
{
throw new \Asika\SimpleConsole\CommandArgsException('Please enter a name.');
}
php
//...
protected function doExecute()
{
return $this->delegate($this->getArgument(0));
}
protected function foo()
{
$this->getArgument(1); // bar
}
protected function baz()
{
// ...
}