From f2459849b043786a10c95896fa9fffb329265f42 Mon Sep 17 00:00:00 2001 From: Alexandre Mercier Date: Fri, 28 Mar 2014 18:22:57 +0100 Subject: [PATCH] Removed Closure::bind to be PHP 5.3 compliant --- src/Cli/Helpers/DocumentedScript.php | 20 ++++++++++---------- src/Cli/Helpers/Script.php | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) 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;