-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from ThomasNunninger/master
Do not create MethodMetadata::$reflection on constructor/unserialize,…
- Loading branch information
Showing
2 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
* properties, and flags. | ||
* | ||
* @author Johannes M. Schmitt <[email protected]> | ||
* | ||
* @property $reflection | ||
*/ | ||
class MethodMetadata implements \Serializable | ||
{ | ||
|
@@ -27,15 +29,12 @@ class MethodMetadata implements \Serializable | |
/** | ||
* @var \ReflectionMethod | ||
*/ | ||
public $reflection; | ||
private $reflection; | ||
|
||
public function __construct(string $class, string $name) | ||
{ | ||
$this->class = $class; | ||
$this->name = $name; | ||
|
||
$this->reflection = new \ReflectionMethod($class, $name); | ||
$this->reflection->setAccessible(true); | ||
} | ||
|
||
/** | ||
|
@@ -45,7 +44,7 @@ public function __construct(string $class, string $name) | |
*/ | ||
public function invoke(object $obj, array $args = []) | ||
{ | ||
return $this->reflection->invokeArgs($obj, $args); | ||
return $this->getReflection()->invokeArgs($obj, $args); | ||
} | ||
|
||
/** | ||
|
@@ -71,8 +70,35 @@ public function serialize() | |
public function unserialize($str) | ||
{ | ||
list($this->class, $this->name) = unserialize($str); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function __get(string $propertyName) | ||
{ | ||
if ('reflection' === $propertyName) { | ||
return $this->getReflection(); | ||
} | ||
|
||
return $this->$propertyName; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __set(string $propertyName, $value): void | ||
{ | ||
$this->$propertyName = $value; | ||
} | ||
|
||
private function getReflection(): \ReflectionMethod | ||
{ | ||
if (null === $this->reflection) { | ||
$this->reflection = new \ReflectionMethod($this->class, $this->name); | ||
$this->reflection->setAccessible(true); | ||
} | ||
|
||
$this->reflection = new \ReflectionMethod($this->class, $this->name); | ||
$this->reflection->setAccessible(true); | ||
return $this->reflection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters