-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2] [FrameworkBundle] Add events to console commands #3889
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
35c6c6a
Addedd events for CLI commands
flevour 41949fb
Removed extra comment
flevour 6d97975
fixed event name and not triggering events for shell
flevour a2ca8f9
remove extra line
flevour 9e05e75
renaming variable
flevour c15265d
removing unuesful RegisterConsoleListenersPass
flevour b1de5ca
Events for console commands execution
flevour c476c98
extending from event and not kernel event
flevour b3c3acf
fix public keyword missing
flevour 7745d7e
integrating feedback from stof
flevour 55b0ed2
renaming ConsoleInitEvent
flevour 0856966
fixed lost use clause
flevour dbb5977
fixed renaming ConsoleInitEvent in ConsoleEvent
flevour bff61be
fix tests for Console/Application
flevour 459a4da
make ConsoleTerminateEvent receive $input and $output as constructor …
flevour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Console; | ||
|
||
/** | ||
* Contains all events thrown during Console commands execution | ||
* | ||
* @author Francesco Levorato <[email protected]> | ||
* | ||
*/ | ||
final class ConsoleEvents | ||
{ | ||
/** | ||
* The INIT event allows you to attach listeners before any command is | ||
* executed by the console. It also allows you to modify the input and output | ||
* before they are handled to the command. | ||
* | ||
* The event listener method receives a \Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleEvent | ||
* instance. | ||
* | ||
* @var string | ||
*/ | ||
const INIT = 'console.init'; | ||
|
||
/** | ||
* The TERMINATE event allows you to attach listeners after a command is | ||
* executed by the console. | ||
* | ||
* The event listener method receives a \Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleTerminateEvent | ||
* instance. | ||
* | ||
* @var string | ||
*/ | ||
const TERMINATE = 'console.terminate'; | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Console\Event; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/** | ||
* Allows to inspect input and output of a command. | ||
* | ||
* @author Francesco Levorato <[email protected]> | ||
*/ | ||
class ConsoleEvent extends Event | ||
{ | ||
|
||
private $input; | ||
|
||
private $output; | ||
|
||
public function __construct(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->input = $input; | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Returns the input object | ||
* | ||
* @return InputInterface | ||
*/ | ||
public function getInput() | ||
{ | ||
return $this->input; | ||
} | ||
|
||
/** | ||
* Returns the output object | ||
* | ||
* @return OutputInterface | ||
*/ | ||
public function getOutput() | ||
{ | ||
return $this->output; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Console\Event; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Allows to receive the exit code of a command after its execution. | ||
* | ||
* @author Francesco Levorato <[email protected]> | ||
*/ | ||
class ConsoleTerminateEvent extends ConsoleEvent | ||
{ | ||
|
||
/** | ||
* The exit code of the command. | ||
* | ||
* @var integer | ||
*/ | ||
private $exitCode; | ||
|
||
public function __construct(InputInterface $input, OutputInterface $output, $exitCode) | ||
{ | ||
parent::__construct($input, $output); | ||
$this->exitCode = $exitCode; | ||
} | ||
|
||
/** | ||
* Returns the exit code. | ||
* | ||
* @return integer | ||
*/ | ||
public function getExitCode() | ||
{ | ||
return $this->exitCode; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one should probably extend from the ConsoleInitEvent (which should then be renamed to ConsoleEvent) to give access to the input and output too |
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line here