1
|
|
|
<?php |
2
|
|
|
namespace Doctrine\Common\Reflection; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Proxy\Proxy; |
5
|
|
|
use ReflectionProperty; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* PHP Runtime Reflection Public Property - special overrides for public properties. |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
class RuntimePublicReflectionProperty extends ReflectionProperty |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritDoc} |
15
|
|
|
* |
16
|
|
|
* Checks is the value actually exist before fetching it. |
17
|
|
|
* This is to avoid calling `__get` on the provided $object if it |
18
|
|
|
* is a {@see \Doctrine\Common\Proxy\Proxy}. |
19
|
|
|
*/ |
20
|
1 |
|
public function getValue($object = null) |
21
|
|
|
{ |
22
|
1 |
|
$name = $this->getName(); |
23
|
|
|
|
24
|
1 |
|
if ($object instanceof Proxy && ! $object->__isInitialized()) { |
25
|
1 |
|
$originalInitializer = $object->__getInitializer(); |
26
|
1 |
|
$object->__setInitializer(null); |
27
|
1 |
|
$val = $object->$name ?? null; |
28
|
1 |
|
$object->__setInitializer($originalInitializer); |
29
|
|
|
|
30
|
1 |
|
return $val; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return isset($object->$name) ? parent::getValue($object) : null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
* |
39
|
|
|
* Avoids triggering lazy loading via `__set` if the provided object |
40
|
|
|
* is a {@see \Doctrine\Common\Proxy\Proxy}. |
41
|
|
|
* @link https://bugs.php.net/bug.php?id=63463 |
42
|
|
|
*/ |
43
|
1 |
|
public function setValue($object, $value = null) |
44
|
|
|
{ |
45
|
1 |
|
if (! ($object instanceof Proxy && ! $object->__isInitialized())) { |
46
|
1 |
|
parent::setValue($object, $value); |
47
|
|
|
|
48
|
1 |
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$originalInitializer = $object->__getInitializer(); |
52
|
1 |
|
$object->__setInitializer(null); |
53
|
1 |
|
parent::setValue($object, $value); |
54
|
1 |
|
$object->__setInitializer($originalInitializer); |
55
|
1 |
|
} |
56
|
|
|
} |
57
|
|
|
|