1. Go to this page and download the library: Download spatie/laravel-eventsauce 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/ */
namespace App\MyDomain;
class CommandHandler
{
/** @var \EventSauce\EventSourcing\AggregateRootRepository */
private $repository;
public function __construct(MyAggregateRootRepository $repository)
{
$this->repository = $repository;
}
public function handle(object $command)
{
$aggregateRootId = $command->identifier();
$aggregateRoot = $this->repository->retrieve($aggregateRootId);
try {
if ($command instanceof MySpecialCommand) {
$aggregateRoot->performMySpecialCommand($command);
}
} finally {
$this->repository->persist($aggregateRoot);
}
}
}
return [
/*
* Types, commands and events can be generated starting from a yaml file.
* Here you can specify the input and the output of the code generation.
*
* More info on code generation here:
* https://eventsauce.io/docs/getting-started/create-events-and-commands
*/
'code_generation' => [
[
'input_yaml_file' => null,
'output_file' => null,
],
],
/*
* This connection name will be used to store messages. When
* set to null the default connection will be used.
*/
'database_connection' => null,
/*
* This class will be used to store messages.
*
* You may change this to any class that implements
* \EventSauce\EventSourcing\MessageRepository
*/
'message_repository' => \Spatie\LaravelEventSauce\MessageRepository::class,
/*
* This class will be used to put EventSauce messages on the queue.
*
* You may change this to any class that extends
* \Spatie\LaravelEventSauce\QueuedMessageJob::class
*/
'queued_message_job' => \Spatie\LaravelEventSauce\QueuedMessageJob::class,
];
use Spatie\LaravelEventSauce\QueuedMessageJob;
class MyCustomJob extends QueuedMessageJob
{
/*
* The name of the connection the job should be sent to.
*/
public $connection = 'my-custom-connection';
/*
* The name of the queue the job should be sent to.
*/
public $queue = 'my-custom-queue';
/*
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;
/*
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 120;
/*
* The number of seconds before the job should be made available.
*
* @var int|null
*/
public $delay;
}