To use one of the existing commands you just need to select the proper bus and select the command you want to use. One bus is created for each user type so select the correct one.
In the following examples EnableUserCommand is used to demonstrate the usage of the command bus. In case you want the
whole list check command reference in the BenGor
User library. The usage is the same, a command instance needs to be passed as first parameter of the handle() method
of the command bus.
In case you are triggering the command from a Symfony controller do the following replacing $userType by your
user type.
$this->get('bengor_user.' . $userType . '.command_bus')->handle(
new EnableUserCommand($confirmationToken)
);
In case you want to trigger the command from a Symfony service you need to
inject it in as usual,
replacing your_user_type by your user type.
# app/config/services.yml
services:
app.your_service:
class: AppBundle\Service\YourService
arguments: ['[@bengor_user](https://github.com/bengor_user).your_user_type.command_bus']
// src/AppBundle/Service/YourService.php
use BenGorUser\User\Infrastructure\CommandBus\UserCommandBus;
class YourService
{
private $commandBus;
public function __construct(UserCommandBus $commandBus)
{
$this->commandBus = $commandBus;
}
public function doWhatever($confirmationToken)
{
$this->commandBus->handle(
new EnableUserCommand($confirmationToken)
);
}
}
How can I help you explore Laravel packages today?