Summary
This chapter covered a great deal of what you could want to do in using and extending Doctrine. Combining events and filters, you can create very solid extensions. Do you want to create a new CMS where articles can only be seen after they are "published"? Events and filters will come along nicely to provide a publishable behavior to your entities. Do you need to keep versions of all changes and know who made what change and when? Here again, the events will allow you to have this taken care of on all entities without worrying about manually doing it.
As an exercise, you can try to implement a soft delete behavior. Soft delete indicates that whenever an entity is about to be deleted, you instead update a deleted field to true, or to the timestamp at which it was deleted. Creating a SoftDeleteable
behavior for your entities should involve both listening to events and using a filter.
I mentioned earlier about Doctrine's Abstract Syntax Tree and how it used to be necessary before Doctrine...