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