-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
define and call standard events for CLI commands #1929
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
Comments
@lsmith77 any news about this ? |
havent had time for this. but should be something for someone who wants to dip their toes in core dev. will try to find a helping hand via twitter. |
@lsmith sounds interesting taking a look |
@lsmith77 can you please elaborate on my personal example use case is wanting to set a dynamic HTTP header in all commands calling a backend through a load balancer that picks the server based on said HTTP header. I am also confused because in the other ticket you said tags, @fabpot reopened it because of it otherwise he would have kept it closed and now this is events again. |
here is an example of a kernel listener, that i would also like to run on the CLI before any command is executed:
so the idea would be that I could also modify the tag section to something like the following
|
@lsmith77 if you implement it using the EventDispatcher, there is no reason to have a different tag name. |
Any progress on this? May I give it a try using the tag approach? |
@flevour i have not worked on it .. and i have not seen anyone else post any progress on this ticket |
@lsmith77 if the tag approach is still the way to go, I'll give it a shot. |
yes it is. |
Sorry, but I need to discuss this a little further. Where would the fix go? I read #1884 a 3 or 4 times to make sure I am understanding the issue. If I understand correctly, the scope of this issue is a bit larger. It's not aiming to solve a specific use case, as in the cache:clear scenario. Instead it's aiming to create a way to solve all possible cases when you want to call a set of services before or after the execution of a command. This would mean calling all properly tagged services at the right moment. That is, modifying ContainerAwareCommand in order to wrap the call to execute() with calls to the tagged services. As this sounds very EventDispatcher-y to me (and your example makes the parallelism even more likely), could you please help me understand why going with tagged services is the way to go and how would you implement it? |
The final code would be in the FrameworkBundle as a new compiler pass. There we would look for the tagged services and connect them to events. The events should themselves be triggered inside |
I published the PR just to gather feedback about the direction I am taking. |
Hi Lukas, when you have 2 mins, please give a look at #3889, I need some pointers to move on. |
This PR was merged into the master branch. Discussion ---------- Console dispatcher | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #3889, #6124 | License | MIT | Doc PR | symfony/symfony-docs#2352 refs #1884, #1929 This is an alternative implementation for adding events to console applications. This implementation has the following features: * Available for anyone using the Console component and it is not tied to FrameworkBundle (this is important as one thing we are trying to solve is email sending from a command, and frameworks like Silex using the Console component needs a solution too); * Non-intrusive as the current code has not been changed (except for renaming an internal variable that was wrongly named -- so that's not strictly needed for this PR) * The new DispatchableApplication class also works without a dispatcher, falling back to the regular behavior. That makes easy to create applications that can benefit from a dispatcher when available, but can still work otherwise. * Besides the *before* and *after* events, there is also an *exception* event that is dispatched whenever an exception is thrown. * Each event is quite powerful and can manipulate the input, the output, but also the command to be executed. Commits ------- 4f9a55a refactored the implementation of how a console application can handle events 4edf29d added helperSet to console event objects f224102 Added events for CLI commands
the idea is to create an equivalent to the kernel events like request, controller, view, response.
this would allow doing common dynamic setup tasks (like doing some dynamic configuration inside a storage API). but it maybe we also want to have additional events fired in other cases, like when an uncaught exception happens or to maintain an audit log of CLI command calls.
my personal example use case is wanting to set a dynamic HTTP header in all commands calling a backend through a load balancer that picks the server based on said HTTP header.
see also #1884 for why a tag and not an event listener
The text was updated successfully, but these errors were encountered: