@@ -5,46 +5,46 @@ |
||
5 | 5 | |
6 | 6 | class ReflectionClass extends \ReflectionClass |
7 | 7 | { |
8 | - /** @var object */ |
|
9 | - protected $object; |
|
10 | - |
|
11 | - public function __construct($object) |
|
12 | - { |
|
13 | - if (!is_object($object)) { |
|
14 | - throw new \InvalidArgumentException(sprintf('Expected "object", got "%s".', gettype($object))); |
|
15 | - } |
|
16 | - |
|
17 | - parent::__construct($object); |
|
18 | - $this->object = $object; |
|
19 | - } |
|
20 | - |
|
21 | - public static function from($class): self |
|
22 | - { |
|
23 | - return new static($class); |
|
24 | - } |
|
25 | - |
|
26 | - public function invokeMethod(string $method, array $arguments = []) |
|
27 | - { |
|
28 | - $reflection = $this->getMethod($method); |
|
29 | - $reflection->setAccessible(true); |
|
30 | - |
|
31 | - return $reflection->invokeArgs($this->object, $arguments); |
|
32 | - } |
|
33 | - |
|
34 | - public function setPropertyValue(string $property, $value): self |
|
35 | - { |
|
36 | - $reflection = $this->getProperty($property); |
|
37 | - $reflection->setAccessible(true); |
|
38 | - $reflection->setValue($this->object, $value); |
|
39 | - |
|
40 | - return $this; |
|
41 | - } |
|
42 | - |
|
43 | - public function getPropertyValue(string $property) |
|
44 | - { |
|
45 | - $reflection = $this->getProperty($property); |
|
46 | - $reflection->setAccessible(true); |
|
47 | - |
|
48 | - return $reflection->getValue($this->object); |
|
49 | - } |
|
8 | + /** @var object */ |
|
9 | + protected $object; |
|
10 | + |
|
11 | + public function __construct($object) |
|
12 | + { |
|
13 | + if (!is_object($object)) { |
|
14 | + throw new \InvalidArgumentException(sprintf('Expected "object", got "%s".', gettype($object))); |
|
15 | + } |
|
16 | + |
|
17 | + parent::__construct($object); |
|
18 | + $this->object = $object; |
|
19 | + } |
|
20 | + |
|
21 | + public static function from($class): self |
|
22 | + { |
|
23 | + return new static($class); |
|
24 | + } |
|
25 | + |
|
26 | + public function invokeMethod(string $method, array $arguments = []) |
|
27 | + { |
|
28 | + $reflection = $this->getMethod($method); |
|
29 | + $reflection->setAccessible(true); |
|
30 | + |
|
31 | + return $reflection->invokeArgs($this->object, $arguments); |
|
32 | + } |
|
33 | + |
|
34 | + public function setPropertyValue(string $property, $value): self |
|
35 | + { |
|
36 | + $reflection = $this->getProperty($property); |
|
37 | + $reflection->setAccessible(true); |
|
38 | + $reflection->setValue($this->object, $value); |
|
39 | + |
|
40 | + return $this; |
|
41 | + } |
|
42 | + |
|
43 | + public function getPropertyValue(string $property) |
|
44 | + { |
|
45 | + $reflection = $this->getProperty($property); |
|
46 | + $reflection->setAccessible(true); |
|
47 | + |
|
48 | + return $reflection->getValue($this->object); |
|
49 | + } |
|
50 | 50 | } |