1. Go to this page and download the library: Download studioignis/cmd 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/ */
studioignis / cmd example snippets
$container = new StudioIgnis\Cmd\CommandBus(
new Acme\Foo\Container($whatever),
new StudioIgnis\Cmd\DefaultNameInflector
);
use StudioIgnis\Cmd\Bus;
class FooController
{
public function __construct(Bus $commandBus)
{
// ...
}
}
namespace Acme\User\Handler;
use StudioIgnis\Cmd\Command;
use StudioIgnis\Cmd\Handler;
use Acme\User\Command\SignUp as SignUpCommand;
class SignUp implements Handler
{
public function handle(UserRepository $users)
{
$this->users = $users;
}
public function handle(Command $command)
{
/** @var SignUpCommand $command */
$this->users->add($command->name, $command->email, $command->password);
}
}
namespace Acme\User\Command;
use StudioIgnis\cmd\Command;
class SignUp extends Command
{
public function __construct($name, $email, $password)
{
$this->attributes = compact('name', 'email', 'password');
}
}
// One by one
$name = $signUpCommand->name;
$email = $signUpCommand->email;
$password = $signUpCommand->password;
// As an array
$signUpCommand->toArray();
// As a json string
$json = $signUpCommand->toJson();
$json = (string) $signUpCommand;
$json = json_encode($signUpCommand);
$command = new \Acme\User\Command\SignUp(
'JohnDoe',
'[email protected],
'password!'
);
$bus->execute($command);