From 14da7c8e961889e34e21200d07438e8d7c0fff45 Mon Sep 17 00:00:00 2001 From: Avindra Goolcharan Date: Fri, 15 Jan 2016 14:26:02 -0500 Subject: [PATCH] [Process] don't populate internal buffer if user closure is supplied --- src/Symfony/Component/Process/Process.php | 12 ++++++------ src/Symfony/Component/Process/README.md | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 2ebda2675d7c4..8ca4d01a93eea 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1211,14 +1211,14 @@ protected function buildCallback($callback) { $out = self::OUT; $callback = function ($type, $data) use ($callback, $out) { - if ($out == $type) { - $this->addOutput($data); - } else { - $this->addErrorOutput($data); - } - if (null !== $callback) { call_user_func($callback, $type, $data); + } else { + if ($out == $type) { + $this->addOutput($data); + } else { + $this->addErrorOutput($data); + } } }; diff --git a/src/Symfony/Component/Process/README.md b/src/Symfony/Component/Process/README.md index 7222fe8957e9d..d1ff2ae450e1f 100644 --- a/src/Symfony/Component/Process/README.md +++ b/src/Symfony/Component/Process/README.md @@ -19,7 +19,7 @@ if (!$process->isSuccessful()) { print $process->getOutput(); ``` -You can think that this is easy to achieve with plain PHP but it's not especially +You may think that this is easy to achieve with plain PHP but it's not especially if you want to take care of the subtle differences between the different platforms. You can simplify the code by using `mustRun()` instead of `run()`, which will @@ -35,9 +35,9 @@ $process->mustRun(); print $process->getOutput(); ``` -And if you want to be able to get some feedback in real-time, just pass an +If you want to be able to get some feedback in real-time, just pass an anonymous function to the ``run()`` method and you will get the output buffer -as it becomes available: +as it becomes available instead: ```php use Symfony\Component\Process\Process;