Skip to content

Commit

Permalink
Removed Closure::bind to be PHP 5.3 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
amercier committed Mar 28, 2014
1 parent c58b7b1 commit f245984
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions src/Cli/Helpers/DocumentedScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
Expand All @@ -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) {
Expand All @@ -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;
}
);
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Helpers/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f245984

Please sign in to comment.