Create a Microservice with Symfony Part 20: Validation, Events and Subscribers (Symfony 6 Tutorial)

preview_player
Показать описание
ℹ This is a series on building a Microservice with Symfony Framework (version 6). In part 20 we'll create an event which is fired when a data transfer object is created. We'll have an event subscriber listen for this event in order to perform validation on the DTO...fun!

💻Source code here:

💻Integrating app source code here:

⭐Check out the Testing PHP course which I mentioned in this recording:

👇Follow me on Social Media:

💕Show support:
Рекомендации по теме
Комментарии
Автор

Thank you Gary, great explanation. Here is some notes from me, maybe for someone it will be useful:
1. it's not necessary to define the name of the event, the class name is enough: AfterDtoCreatedEvent::class => 'validateDto'
2. in your test the container also not necessary, you can create dispatcher by handle, so it will be like below:
$dispatcher = new EventDispatcher();
$event = new AfterDtoCreatedEvent($dto);
$subscriber = new DtoSubscriber($validator);

//your expectation checks here

sergeidavidenko
Автор

Hi Gary I don't understand the Philosophie why you used the events and not just using validation without events subscribers....

yasineelbrihi
Автор

Thank you, that was a good explanation, and what's more important, done on the newest version of Symfony :)

szymondoerfer