You must use an event subscriber if you want to deal with several events in the same class, for example, in this page of the symfony2 doc article , you can note that the event listener can only manage one event, but lets say that you want to deal with several events for one object, prePersist, preUpdate, postPersist, etc. .... if you use an event listener, you will have to encode several event listeners, one for each event, but if you go with an event subscriber, you if you need to encode one class on a suspicious event, look that with the event subscriber you can manage several events in one class, well, hereβs how I use it, I prefer to focus the code on what the model business needs, one example of this might be that you want to handle several globaly life cycle events only for a group of your entities, to do this, you can encode the parent class and define these global methods in it, and then make your objects inherit this class, Later in your case susbcriber signed by each eve nt you want, prePersist, preUpdate, postPersist, etc., and then ask the parent class and do these global methods.
metalvarez Nov 21 '13 at 16:09 2013-11-21 16:09
source share