-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Console dispatcher #7466
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
Merged
Merged
Console dispatcher #7466
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,55 @@ | ||
<?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\Component\Console; | ||
|
||
/** | ||
* Contains all events dispatched by an Application. | ||
* | ||
* @author Francesco Levorato <[email protected]> | ||
*/ | ||
final class ConsoleEvents | ||
{ | ||
/** | ||
* The COMMAND event allows you to attach listeners before any command is | ||
* executed by the console. It also allows you to modify the command, input and output | ||
* before they are handled to the command. | ||
* | ||
* The event listener method receives a Symfony\Component\Console\Event\ConsoleCommandEvent | ||
* instance. | ||
* | ||
* @var string | ||
*/ | ||
const COMMAND = 'console.command'; | ||
|
||
/** | ||
* The TERMINATE event allows you to attach listeners after a command is | ||
* executed by the console. | ||
* | ||
* The event listener method receives a Symfony\Component\Console\Event\ConsoleTerminateEvent | ||
* instance. | ||
* | ||
* @var string | ||
*/ | ||
const TERMINATE = 'console.terminate'; | ||
|
||
/** | ||
* The EXCEPTION event occurs when an uncaught exception appears. | ||
* | ||
* This event allows you to deal with the exception or | ||
* to modify the thrown exception. The event listener method receives | ||
* a Symfony\Component\Console\Event\ConsoleForExceptionEvent | ||
* instance. | ||
* | ||
* @var string | ||
*/ | ||
const EXCEPTION = 'console.exception'; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Symfony/Component/Console/Event/ConsoleCommandEvent.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,25 @@ | ||
<?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\Component\Console\Event; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Allows to do things before the command is executed. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class ConsoleCommandEvent extends ConsoleEvent | ||
{ | ||
} |
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,67 @@ | ||
<?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\Component\Console\Event; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
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 | ||
{ | ||
protected $command; | ||
|
||
private $input; | ||
private $output; | ||
|
||
public function __construct(Command $command, InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->command = $command; | ||
$this->input = $input; | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Gets the command that is executed. | ||
* | ||
* @return Command A Command instance | ||
*/ | ||
public function getCommand() | ||
{ | ||
return $this->command; | ||
} | ||
|
||
/** | ||
* Gets the input instance. | ||
* | ||
* @return InputInterface An InputInterface instance | ||
*/ | ||
public function getInput() | ||
{ | ||
return $this->input; | ||
} | ||
|
||
/** | ||
* Gets the output instance. | ||
* | ||
* @return OutputInterface An OutputInterface instance | ||
*/ | ||
public function getOutput() | ||
{ | ||
return $this->output; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Symfony/Component/Console/Event/ConsoleForExceptionEvent.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,67 @@ | ||
<?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\Component\Console\Event; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Allows to handle exception thrown in a command. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class ConsoleForExceptionEvent extends ConsoleEvent | ||
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. Why "For"? "ConsoleExceptionEvent" seems more consistent with the other ones. 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. @fabpot did you just miss this? I don't understand the class name either. |
||
{ | ||
private $exception; | ||
private $exitCode; | ||
|
||
public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode) | ||
{ | ||
parent::__construct($command, $input, $output); | ||
|
||
$this->setException($exception); | ||
$this->exitCode = $exitCode; | ||
} | ||
|
||
/** | ||
* Returns the thrown exception. | ||
* | ||
* @return \Exception The thrown exception | ||
*/ | ||
public function getException() | ||
{ | ||
return $this->exception; | ||
} | ||
|
||
/** | ||
* Replaces the thrown exception. | ||
* | ||
* This exception will be thrown if no response is set in the event. | ||
* | ||
* @param \Exception $exception The thrown exception | ||
*/ | ||
public function setException(\Exception $exception) | ||
{ | ||
$this->exception = $exception; | ||
} | ||
|
||
/** | ||
* Gets the exit code. | ||
* | ||
* @return integer The command exit code | ||
*/ | ||
public function getExitCode() | ||
{ | ||
return $this->exitCode; | ||
} | ||
} |
Oops, something went wrong.
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.
the typehint should be the interface