diff --git a/src/Cli/Helpers/DocumentedScript.php b/src/Cli/Helpers/DocumentedScript.php index c2e0c66..7c5b4f6 100644 --- a/src/Cli/Helpers/DocumentedScript.php +++ b/src/Cli/Helpers/DocumentedScript.php @@ -15,9 +15,9 @@ protected function addVersionParameter() $this->addParameter( new Parameter('V', 'version', Parameter::VALUE_NO_VALUE), 'Output version information and exit.', - function ($options, $arguments) { - echo $this->name . ' v' . $this->version . "\n" - . ($this->copyright ? $this->copyright . "\n" : ''); + function ($options, $arguments, $that) { + echo $that->name . ' v' . $that->version . "\n" + . ($that->copyright ? $that->copyright . "\n" : ''); return false; } ); @@ -28,11 +28,11 @@ protected function addHelpParameter() $this->addParameter( new Parameter('h', 'help', Parameter::VALUE_NO_VALUE), 'Display this help and exit.', - function ($options, $arguments) { + function ($options, $arguments, $that) { echo 'Usage: ' . $arguments[0]; $lines = array(); - foreach ($this->parameters as $id => $parameter) { + foreach ($that->parameters as $id => $parameter) { // Show in syntax line if required if ($parameter->getDefaultValue() === Parameter::VALUE_REQUIRED) { @@ -55,22 +55,22 @@ function ($options, $arguments) { ? preg_replace( '/(\\.)?$/', ' (defaults to \'' . $parameter->getDefaultValue() . '\')$1', - $this->parameterDescriptions[$id], + $that->parameterDescriptions[$id], 1 ) - : $this->parameterDescriptions[$id] + : $that->parameterDescriptions[$id] ), ); } echo " [OPTIONS]\n" . "\n" - . $this->description . "\n" + . $that->description . "\n" . "\n" . IO::strPadAll($lines, array(), "\n", ' ', ' ', false) . "\n" . "\n" - . $this->name . ' v' . $this->version . "\n" - . ($this->copyright ? $this->copyright . "\n" : ''); + . $that->name . ' v' . $that->version . "\n" + . ($that->copyright ? $that->copyright . "\n" : ''); return false; } ); diff --git a/src/Cli/Helpers/Script.php b/src/Cli/Helpers/Script.php index 4a9c816..ce49e6f 100644 --- a/src/Cli/Helpers/Script.php +++ b/src/Cli/Helpers/Script.php @@ -140,9 +140,9 @@ protected function processParameters($arguments) */ protected function run($arguments) { - $program = Closure::bind($this->program, $this); + $program = $this->program; if (!$this->exceptionCatchingEnabled) { - return $program($this->initParameters($arguments), $arguments); + return $program($this->initParameters($arguments), $arguments, $this); } try { @@ -209,7 +209,7 @@ public function addParameter($parameter, $description, $callback = null) if ($parameter->getDefaultValue() !== Parameter::VALUE_NO_VALUE) { throw new Exception\InvalidScriptParameter($parameter); } - $this->parameterCallbacks[$id] = Closure::bind($callback, $this); + $this->parameterCallbacks[$id] = $callback; } return $this;