-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Bind the closure (code) to the Command if possible #14431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,6 +284,13 @@ public function setCode($code) | |
throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.'); | ||
} | ||
|
||
if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) { | ||
$r = new \ReflectionFunction($code); | ||
if (null === $r->getClosureThis()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ? This is precisely the case where we add a new feature There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok I understand now :D , |
||
$code = \Closure::bind($code, $this); | ||
} | ||
} | ||
|
||
$this->code = $code; | ||
|
||
return $this; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the PHP version check necessary? In PHP 5.3 the instanceof check will return false, as the
Closure
class doesn't exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, but what if someone define a user-land
Closure
class ?IHMO, it's safer to keep the version check (and will be removed in SF3.0 anyway)
edit: I did not know Closure exists since php 5.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Closure class exists since 5.3, but Closure::bind has been introduced in 5.4, so the check is required :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! :)