1. Go to this page and download the library: Download amonger/command 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/ */
amonger / command example snippets
namespace Command\Command;
class MyHandlerCommand
{
public $someParam;
public function __construct($someParam)
{
$this->someParam = $someParam;
}
}
namespace Command\Handler;
class MyHandlerHandler implements HandlerInterface, ApplicationInterface
{
protected $app;
public function handle($object)
{
echo $app['db']->persist($object->someParam);
}
public function setApplication($app)
{
$this->app = $app;
}
}
$command = new Command\Command(new Command\Resolver);
$command->setApplication($app);
$command->dispatch(new MyHandlerCommand($someParam));
namespace Command\Command;
class MyHandlerCommand implements SelfHandling
{
protected $someParam;
public function __construct($someParam)
{
$this->someParam = $someParam;
}
public function handle()
{
return $this->someParam * 2;
}
}
class TestCommand implements SelfHandling, ApplicationInterface
{
private $name;
private $application;
public function __construct($name)
{
$this->name = $name;
}
public function handle()
{
$app = $this->application;
var_dump($app($this->name));
}
/**
* @param $application
* @return void
*/
public function setApplication($application)
{
$this->application = $application;
}
}
$resolver = new \Command\Resolver\SelfHandlingResolver();
$resolver->setApplication(function($a){ return $a*2;});
$command = new Command\Command($resolver);
$command->dispatch(new TestCommand(2));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.