Multiple fixes

This commit is contained in:
Carlos Buenosvinos
2022-03-26 19:00:52 +01:00
parent fcadf1c709
commit 41a25c123a
4 changed files with 51 additions and 1 deletions

View File

@@ -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'

View File

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

View File

@@ -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

View File

@@ -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
}
}