Multiple fixes
This commit is contained in:
@@ -119,6 +119,9 @@ services:
|
||||
Cheeper\Chapter7\DomainModel\Follow\FollowRepository:
|
||||
class: 'Cheeper\Chapter7\Infrastructure\DomainModel\Follow\DoctrineOrmFollowRepository'
|
||||
|
||||
Cheeper\Chapter7\DomainModel\Notifier\Notifier:
|
||||
class: 'Cheeper\Chapter7\Infrastructure\DomainModel\Notifier\NullNotifier'
|
||||
|
||||
Cheeper\Chapter7\Application\CommandBus:
|
||||
class: 'Cheeper\Chapter7\Infrastructure\Application\SymfonyCommandBus'
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cheeper\Chapter7\Application\Author\Event\AuthorFollowed;
|
||||
namespace Cheeper\Chapter7\Application\Author\Event\NewAuthorSigned;
|
||||
|
||||
use Cheeper\Chapter7\Application\Author\Command\WelcomeCommand;
|
||||
use Cheeper\Chapter7\Application\CommandBus;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cheeper\Chapter7\Infrastructure\Application;
|
||||
|
||||
use Cheeper\Chapter7\Application\CommandBus;
|
||||
use function Functional\first;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\HandlerFailedException;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
// snippet symfony-command-bus
|
||||
final class SymfonyCommandBus implements CommandBus
|
||||
{
|
||||
public function __construct(
|
||||
private MessageBusInterface $commandBus
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(object $command): Envelope
|
||||
{
|
||||
try {
|
||||
$envelope = $this->commandBus->dispatch($command);
|
||||
} catch (HandlerFailedException $exception) {
|
||||
throw first($exception->getNestedExceptions());
|
||||
}
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
}
|
||||
//end-snippet
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cheeper\Chapter7\Infrastructure\DomainModel\Notifier;
|
||||
|
||||
use Cheeper\Chapter7\DomainModel\Author\Author;
|
||||
|
||||
final class NullNotifier
|
||||
{
|
||||
public function notify(Author $author): void
|
||||
{
|
||||
// Send email or do whatever
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user