bug #37000 Add meaningful message when using ProcessHelper and Process is not installed (l-vo)

This PR was submitted for the master branch but it was merged into the 3.4 branch instead.

Discussion
----------

Add meaningful message when using ProcessHelper and Process is not installed

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

When using the process helper without the `Process` component, a php fatal error is triggered (`PHP Fatal error:  Uncaught Error: Class 'Symfony\Component\Process\Process' not found`). This PR adds a meaningful exception; allowing to display a console error message instead of a raw php fatal error.

Commits
-------

3ab76e40ff Add meaningful message when Process is not installed (ProcessHelper)
This commit is contained in:
Fabien Potencier 2020-05-29 05:22:53 +02:00
commit b7cd22cbc0
1 changed files with 4 additions and 0 deletions

View File

@ -37,6 +37,10 @@ class ProcessHelper extends Helper
*/
public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
{
if (!class_exists(Process::class)) {
throw new \LogicException('The Process helper requires the "Process" component. Install "symfony/process" to use it.');
}
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}