Skip to content

Commit

Permalink
Fix closure output so that it only applies to that run
Browse files Browse the repository at this point in the history
I mistakenly hacked in the functionality using the current displayStdout functionality
which was incorrect. Needs to only use that function on the output of the current
command, and not set it across the board.
  • Loading branch information
MrRio committed Dec 23, 2013
1 parent e96a350 commit 38b4de3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MrRio/ShellWrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ private static function __run($arguments)
{
// Unwind the args, figure out which ones were passed in as an array
self::$stdin = null;
$closureOut = false;

foreach ($arguments as $arg_key => $argument) {
// If it's being passed in as an object, then pipe into stdin
if (is_object($argument)) {

// If it's a anonymous function, then push stdout into it
if (get_class($argument) == 'Closure') {
self::$displayStdout = $argument;
$closureOut = $argument;
unset($arguments[$arg_key]);
} else {
self::$stdin = strval($argument);
Expand Down Expand Up @@ -155,6 +156,9 @@ private static function __run($arguments)
$outputFunction($stdout);
}

if (is_callable($closureOut)) {
$closureOut($stdout);
}
$output .= $stdout;
}

Expand Down

0 comments on commit 38b4de3

Please sign in to comment.