PHP code example of studioignis / cmd

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
);

    'providers' => [
        // ...
        'StudioIgnis\Cmd\Laravel\ServiceProvider',
    ],

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);
    }
}

$bus->setHandler(
    'Acme\User\Command\CreateUser',
    'Acme\User\Command\CreateUserHandler'
);

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);


$input = [
    'name' => $this->input->get('name'),
    'email' => $this->input->get('email'),
    'password' => $this->input->get('password'),
];

$this->cmd('Acme\User\Command\SignUp', $input);