| @@ 23-41 (lines=19) @@ | ||
| 20 | /** |
|
| 21 | * {@inheritdoc} |
|
| 22 | */ |
|
| 23 | public function inject($object, string $property, $value) |
|
| 24 | { |
|
| 25 | if (!$this->supports($object, $property, $value)) { |
|
| 26 | throw new LogicException; |
|
| 27 | } |
|
| 28 | ||
| 29 | $refl = new \ReflectionObject($object); |
|
| 30 | $refl = $refl->getProperty($property); |
|
| 31 | ||
| 32 | if (!$refl->isPublic()) { |
|
| 33 | $refl->setAccessible(true); |
|
| 34 | } |
|
| 35 | ||
| 36 | $refl->setValue($object, $value); |
|
| 37 | ||
| 38 | if (!$refl->isPublic()) { |
|
| 39 | $refl->setAccessible(false); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| @@ 24-43 (lines=20) @@ | ||
| 21 | /** |
|
| 22 | * {@inheritdoc} |
|
| 23 | */ |
|
| 24 | public function extract($object, string $property) |
|
| 25 | { |
|
| 26 | if (!$this->supports($object, $property)) { |
|
| 27 | throw new LogicException; |
|
| 28 | } |
|
| 29 | ||
| 30 | $refl = $this->property($object, $property); |
|
| 31 | ||
| 32 | if (!$refl->isPublic()) { |
|
| 33 | $refl->setAccessible(true); |
|
| 34 | } |
|
| 35 | ||
| 36 | $value = $refl->getValue($object); |
|
| 37 | ||
| 38 | if (!$refl->isPublic()) { |
|
| 39 | $refl->setAccessible(false); |
|
| 40 | } |
|
| 41 | ||
| 42 | return $value; |
|
| 43 | } |
|
| 44 | ||
| 45 | private function property($object, string $property): \ReflectionProperty |
|
| 46 | { |
|