Skip to content

Commit

Permalink
feature #32418 [Console] Added Application::reset() (lyrixx)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

[Console] Added Application::reset()

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Symfony leaks a lot in CLI when using the EventDispatcher. I'm working on it.

But instead of fixing the root cause, it can be legit to go quick and to reset all services.
So IMHO, this services should be exposed, and always available

Commits
-------

15ba579 [Console] Added Application::reset()
  • Loading branch information
fabpot committed Jul 8, 2019
2 parents 400eaa6 + 15ba579 commit 7647209
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Expand Up @@ -55,6 +55,16 @@ public function getKernel()
return $this->kernel;
}

/**
* {@inheritdoc}
*/
public function reset()
{
if ($this->kernel->getContainer()->has('services_resetter')) {
$this->kernel->getContainer()->get('services_resetter')->reset();
}
}

/**
* Runs the current application.
*
Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -45,6 +45,7 @@
use Symfony\Component\ErrorCatcher\Exception\FatalThrowableError;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Contracts\Service\ResetInterface;

/**
* An Application is the container for a collection of commands.
Expand All @@ -61,7 +62,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Application
class Application implements ResetInterface
{
private $commands = [];
private $wantHelps = false;
Expand Down Expand Up @@ -276,6 +277,13 @@ public function doRun(InputInterface $input, OutputInterface $output)
return $exitCode;
}

/**
* {@inheritdoc}
*/
public function reset()
{
}

public function setHelperSet(HelperSet $helperSet)
{
$this->helperSet = $helperSet;
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Component/Console/CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* added `Question::setTrimmable` default to true to allow the answer to be trimmed
* added method `preventRedrawFasterThan()` and `forceRedrawSlowerThan()` on `ProgressBar`
* `Application` implements `ResetInterface`

4.3.0
-----
Expand Down Expand Up @@ -38,7 +39,7 @@ CHANGELOG

* `OutputFormatter` throws an exception when unknown options are used
* removed `QuestionHelper::setInputStream()/getInputStream()`
* removed `Application::getTerminalWidth()/getTerminalHeight()` and
* removed `Application::getTerminalWidth()/getTerminalHeight()` and
`Application::setTerminalDimensions()/getTerminalDimensions()`
* removed `ConsoleExceptionEvent`
* removed `ConsoleEvents::EXCEPTION`
Expand All @@ -64,7 +65,7 @@ CHANGELOG
with value optional explicitly passed empty
* added console.error event to catch exceptions thrown by other listeners
* deprecated console.exception event in favor of console.error
* added ability to handle `CommandNotFoundException` through the
* added ability to handle `CommandNotFoundException` through the
`console.error` event
* deprecated default validation in `SymfonyQuestionHelper::ask`

Expand All @@ -80,7 +81,7 @@ CHANGELOG
-----

* added truncate method to FormatterHelper
* added setColumnWidth(s) method to Table
* added setColumnWidth(s) method to Table

2.8.3
-----
Expand Down

0 comments on commit 7647209

Please sign in to comment.