1. Go to this page and download the library: Download toobo/sealion 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/ */
use Toobo\SeaLion\Router;
/**
* An helper function to output some text in the console
**/
function writeLine($text) {
$f = fopen('php://stdout', 'w');
fwrite($f, $text.PHP_EOL);
fclose($f);
}
// In this trivial example we just have an array of callbacks
// where the one to execute is choosed based on the route
$handlers = [
'handler0' => function($command, array $input) {
writeLine('Command executed: '.$command);
writeLine('Arguments used: '.json_encode($input[Router::ARGUMENTS]));
writeLine('Options used: '.json_encode($input[Router::OPTIONS]));
writeLine('Flags used: '.json_encode($input[Router::FLAGS]));
},
'handler1' => function($command, $input) {
// do something interesting
},
'error' => function($errorBitmask, $command) {
writeLine('Something gone wrong.');
// let's use bitmask of error constants to output error message
if ($command === false) {
writeLine('No or invalid command was used.');
} else {
writeLine('The command '.$command.' was not used properly:');
if ($errorBitmask & Router::ARGS_NOT_MATCHED) {
writeLine('Arguments used were not valid.');
}
if ($errorBitmask & Router::OPTIONS_NOT_MATCHED) {
writeLine('Options used were not valid.');
}
if ($errorBitmask & Router::FLAGS_NOT_MATCHED) {
writeLine('Options used were not valid.');
}
}
}
];
$router = new Router();
// add some commands and respective handlers
$router->addCommand('com1', 'handler0')->withArguments([true]); // 1st arg is
use Toobo\SeaLion\Router;
use Toobo\SeaLion\Input\StringInput;
$input = new StringInput('greet Good Morning --yell -name="Giuseppe"');
$router = new Router($input);
use Toobo\SeaLion\Router;
use Toobo\SeaLion\Input\ArgvInput;
$input = new ArgvInput(['greet', 'Good', 'Morning', '--yell', '-name="Giuseppe"']);
$router = new Router($input);
$dispatcher = new MyCustomDispatcher();
$router = new Router(null, $dispatcher);
php app.php greet good morning -to="Giuseppe" --yell
php app.php greet --yell Good Morning -to=Giuseppe
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.