0

I have an Event Listener that finds an entity object in the database an checks whether current user is authorized for it. I need this object further in Controller, so my question is: what is the best way to pass an object from Event listener to Controller?

I have several options, but none of them is good enough.

  1. In Controller, using repository to fetch the same object from database second time - which is actually less coupled but produces additional DB query.
  2. Serializing object in Event Listener and passing it to Controller in request.
  3. Making a service that will set() object in Event Listener and get() in Controller - but it looks like architectural flaw to assign service for such purposes.

Maybe anyone has better solution?

5
  • how does the application know if the current user is authorized for it? Commented Oct 12, 2015 at 11:37
  • By registering the event listener to service container and than use the service container in controller? Link Commented Oct 12, 2015 at 11:40
  • right.. I think the answer is already given. Commented Oct 12, 2015 at 11:45
  • i protect my objects with custom voters: symfony.com/doc/current/cookbook/security/voters.html Commented Oct 12, 2015 at 11:47
  • @Frankbeen: actually, this is not about authorization, but yes, I use security voters, and still need some processing before and after, so it looks like job for Pre-filters. Commented Oct 12, 2015 at 12:32

1 Answer 1

1

An Event Listener is a service like any other service. You can save your object to a protected member of your service, create a getter for it and in the controller get this service and retrieve the objet using the getter

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed... But isn't this implicit in some way? I mean, Event Listener is not responsible for storing objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.