I found useful pattern for simple callback classes with event(s) as their parameter. Basically I don't have to generate “anonymous” class for using some service on event.

ie instead of

class GenericLogOnEventSubscriber implements Subscriber
{
    function _construct(Logger $logger, $event, $format)

    function getSubscribedEvents() {
        return [ $this->event => 'eventHandler' ];
    }

    function eventHandler() {
        $this->logger->log(spritfv($format, func_get_args()))
    }

I have registered similar service with subscriber tag but it is not subscribed to event. Any suggestions?

I could solve it by moving $event to constant and overriding it in GenericLogOnEventSubscriber descendant (generated class) but that I want to avoid for now. (Until there is cosy anonymous class generator available for DI).

Would be possible to somehow support dynamic getSubscribedEvents marked by @dynamic or implementing DynamicSubscriber instead Subscriber and insert those events? If it would be too hard I would rather implement class templates for DI then spend time on such feature.

As this is more of a feature request, and particularly hard one, let's continue the discussion on github: https://github.com/…ts/issues/63


You must first log in to participate in this discussion