Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static SubscribingHandlerInterface::getSubscribingMethod #380

Closed
ogizanagi opened this issue Jan 5, 2015 · 1 comment
Closed

Static SubscribingHandlerInterface::getSubscribingMethod #380

ogizanagi opened this issue Jan 5, 2015 · 1 comment

Comments

@ogizanagi
Copy link

I wonder if the getSubscribingMethods method of the SubscribingHandlerInterface needs to be static ?
IMO, this is limiting, as we could not access to the handler instance properties.
Accessing it might be useful in order to configure the supported formats and types from a service container definition.

e.g: I've got a basic Enum class. This Enum class is extended from 3 other classes, doing the same things, but defining different constants. The serializer must do the exact same work for those classes. So in order to do that, I'd like to do such a thing in a Symfony 2 application:

#serializer.yml
services:

    acme_demo.serializer.handler.enum_one:
        class: Acme\DemoBundle\Serializer\Handler\EnumHandler
        arguments: [Acme\DemoBundle\Enum\EnumOne]
        tags:
            - { name: jms_serializer.subscribing_handler }

    acme_demo.serializer.handler.enum_two:
        class: Acme\DemoBundle\Serializer\Handler\EnumHandler
        arguments: [Acme\DemoBundle\Enum\EnumTwo]
        tags:
            - { name: jms_serializer.subscribing_handler }

    acme_demo.serializer.handler.enum_three:
        class: Acme\DemoBundle\Serializer\Handler\EnumHandler
        arguments: [Acme\DemoBundle\Enum\EnumThree]
        tags:
            - { name: jms_serializer.subscribing_handler }

The given argument will be the supported type for the handler instance.

I think my example could be solved easily when the #377 will be merged. But there could be other use cases.

@goetas
Copy link
Collaborator

goetas commented Apr 24, 2017

Closing, Sorry for the long feedback loop. This is a common pattern for event-handing, the advantages for a static method are that event registration is context free and can be done at build stage. (see symfony event dispatcher)

@goetas goetas closed this as completed Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants