Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/05/2021 in all areas

  1. Doctrine's event system is specifically designed to let you deal hook into the entity processing/database management system. That's the only thing they are really good for. If that's what you want to do then you'll probably want to use doctrine's events to accomplish your goal. Symfony's event system is just a generic event system that lets a person define events in one area and then subscribe to them in another area. You'd use these whenever you want to design a system where you want or need to be able to extend the functionality in some way or just keep track of what's going on. For example, I have a system where a user creates a committee of other users which then has the be approved later on by an administrator. The code that handles the approval just sets the approved timestamp then dispatches a "Committee Approved" event using the Symfony system. I then have a separate class which subscribes to that event and handles sending email notifications that the committee was approved. I split these tasks by using an event for a couple reasons The code is cleaner this way Maybe someday I'll want to do other things "when a committee is approved" and can just add another subscriber rather than mess with the approval code. Just the way someone decided to do it I'd imagine. You could do it differently if you want. I don't use generic namespaces/folders like that and prefer to be more specific when possible. For example, that committee approval notification is in src/Notification/CommitteeApprovedEmailer.php. The doctrine documentation seems to suggest that you can listen for multiple events in a single class. How you'd accomplish such a thing via Symfony's configuration file I don't know. Symfony might have limit it to a single event, or maybe you can pass an array to event: to define multiple. One would have to experiment or dig into the source code to find out for sure.
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.