Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Added events for CLI commands#6124

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
bamarni wants to merge5 commits intosymfony:masterfrombamarni:standard-events-cli
Closed

[FrameworkBundle] Added events for CLI commands#6124

bamarni wants to merge5 commits intosymfony:masterfrombamarni:standard-events-cli

Conversation

@bamarni
Copy link
Contributor

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

Fixes the following tickets:#1929,#3889

I've allowed myself to continue the effort from@flevour in#3889 as it was only missing unit tests and a small tweak from my pov, I've kept the authorship in the commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would move the event object outside theConsole namespace

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You meanSymfony\Bundle\FrameworkBundle\Event\ConsoleEvent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

exactly

@lsmith77
Copy link
Contributor

+1

1 similar comment
@everzet
Copy link
Contributor

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Better do anisset($this->dispatcher) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why the isSilent here ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@rande : I think it's better to check it here too, relying only on whether or not the dispatcher is there is not entirely true as it is just an optimization of the current application, avoiding the service to be build when it is not needed, checking here too makes the command more robust.

@lolautruche : I don't think it is a big deal, and I often see this withoutisset() in symfony code.

@lolautruche
Copy link
Contributor

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Whether

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

thx, fixed

@DenisGorbachev
Copy link

I second this PR, very much needed.

@bamarni
Copy link
ContributorAuthor

What are the use-cases for this? The only one I saw was the swiftmailer
command to send emails from the spool, which currently fails when it
comes to memory spool, as it uses the kernel.terminate event.

Ideally this capability should be on top of ContainerAwareCommand not to
mess up the Application, here I've kind of blindly implemented what was
discussed on the original ticket, which was to add this on all commands
excepted cache:clear, but it just leads to a dirty hack imo.

Excepted commands one define himself, most of them are just isolated
tools for the application / developer, as such it looks weird to me to
know that potentially emails could be sent when I run any of them.

I'd suggest to have an EventDispatchingCommand extending
ContainerAwareCommand, and that's it. I'd also suggest to provide traits
support for this, which should be the best way to easily plug
capabilities to commands on the long-term whitout running into hacks.

What do you think?

@stof
Copy link
Member

stof commentedDec 8, 2012

I see another use case: setting the base url in the routing RequestContext so that generated urls are right.

and for Swiftmailer, it would send emails only if your command send an email. The MemorySpool will never send an email spooled in a different proces.

I don't like the idea of introducing a separate class for this. It would mean that every developer writing a command would have to decide if the command will dispatch events or no, making it confusing for people using the event ("Why don't I see the event for this command ?")

@bamarni
Copy link
ContributorAuthor

For the swiftmailer issue my fault indeed it's about sending emails from
commands with the memory setting, and for your other use case yes it's
interesting, while those use cases are very common (eg. newsletter), I
don't see why they should affect all other commands, people needing
those kind of feature could just extend a command on top of
ContainerAwareCommand (EventDispatchingCommand or even AbstractCommand
to allow new features later on),

I'm not against making all commands dispatching events in the absolute,
but unfortunately it complicates the code, remember it'd also forces us
to allow disabling it (cache clear command) or to somehow manually
disabling it for this command, while I could practically revert all the
changes of this PR if we choose my first suggestion and come up with a
single class addition.

@lsmith77
Copy link
Contributor

my initial use case was a header I had to set on specific http connections that were triggered both on the web site as well as CLI.

@bamarni
Copy link
ContributorAuthor

I've just took time to look at it and I've been able to implement@stof suggestion without so much pain, so I'm fine with all commands dispatching events.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why the dispatcher here ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

typo => container
Le 9 déc. 2012 15:07, "Christophe Coevoet"notifications@github.com a
écrit :

In src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:

{

  • protected $dispatcher;

why the dispatcher here ?


Reply to this email directly or view it on GitHubhttps://github.com//pull/6124/files#r2358459.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

This adds an init and terminate event for commands. They aredispatched from ContainerAwareCommand.The cache:clear command can't implement this (cf.#3889 on Github).
@bamarni
Copy link
ContributorAuthor

from my pov this PR is now finished.

@ghost
Copy link

@bamarni - I think you need to rebase this to current master as it cannot be automatically merged as it stands.

Conflicts:src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
@bamarni
Copy link
ContributorAuthor

argh... it should be fixed now, thx

@bamarni
Copy link
ContributorAuthor

Is it too late for adding this to 2.2? As a reminder this in not only a new feature, but it'd provide a way to fix a bug, with the standard edition, by default, all mails sent from commands are lost (cf. symfony/symfony-standard#249).

cc@fabpot

@lsmith77
Copy link
Contributor

ping

@attilabukor
Copy link
Contributor

I think it would be nice to have it in 2.2 too.

@rande
Copy link
Contributor

+1000

@marcospassos
Copy link

+1

@marcospassos
Copy link

IMO the dialog helper should be passed through the event. I've an use case of a multitenant application that I need to ask the host before some commands are executed (like doctrine:*), in order to set the RequestContext.

@XWB
Copy link
Contributor

XWB commentedFeb 5, 2013

+1 I was looking for such an implementation, it would be nice to have it in 2.2

@fabpot ping

@startupz
Copy link

I need it too

@fabpot ping

@bamarni
Copy link
ContributorAuthor

I've added the helperSet as per@marcospassos suggestion and also made the tests more robusts by checking both events are getting dispatched properly.

@startupz
Copy link

Up

@XWB
Copy link
Contributor

XWB commentedFeb 22, 2013

@fabpot ping

@bamarni
Copy link
ContributorAuthor

there is no need to ping I guess :) 2.2 is in rc now, so it's obviously too late, and this is not the best moment for the core team to review 2.3 features.

@XWB
Copy link
Contributor

XWB commentedFeb 22, 2013

Fair enough :)

@lsmith77
Copy link
Contributor

i guess now its time to ping again :)

@XWB
Copy link
Contributor

XWB commentedMar 7, 2013

@fabpot ping ;)

@fabpot
Copy link
Member

closing in favor of#7466

@fabpotfabpot closed thisMar 25, 2013
fabpot added a commit that referenced this pull requestMar 25, 2013
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#2352refs#1884,#1929This 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 events4edf29d added helperSet to console event objectsf224102 Added events for CLI commands
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

16 participants

@bamarni@lsmith77@everzet@lolautruche@DenisGorbachev@stof@attilabukor@rande@marcospassos@XWB@startupz@fabpot@pborreli@Tobion@alvarezmario@flevour

[8]ページ先頭

©2009-2025 Movatter.jp