summaryrefslogtreecommitdiff
path: root/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimePublicReflectionProperty.php
blob: e2367ec173faf356c593a93f7997c58020c89d64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

declare(strict_types=1);

namespace Doctrine\Persistence\Reflection;

use Doctrine\Common\Proxy\Proxy;
use ReflectionProperty;
use ReturnTypeWillChange;

/**
 * PHP Runtime Reflection Public Property - special overrides for public properties.
 *
 * @deprecated since version 3.1, use RuntimeReflectionProperty instead.
 */
class RuntimePublicReflectionProperty extends ReflectionProperty
{
    /**
     * {@inheritDoc}
     *
     * Returns the value of a public property without calling
     * `__get` on the provided $object if it exists.
     *
     * @return mixed
     */
    #[ReturnTypeWillChange]
    public function getValue($object = null)
    {
        return $object !== null ? ((array) $object)[$this->getName()] ?? null : parent::getValue();
    }

    /**
     * {@inheritDoc}
     *
     * Avoids triggering lazy loading via `__set` if the provided object
     * is a {@see \Doctrine\Common\Proxy\Proxy}.
     *
     * @link https://bugs.php.net/bug.php?id=63463
     *
     * @param object|null $object
     * @param mixed       $value
     *
     * @return void
     */
    #[ReturnTypeWillChange]
    public function setValue($object, $value = null)
    {
        if (! ($object instanceof Proxy && ! $object->__isInitialized())) {
            parent::setValue($object, $value);

            return;
        }

        $originalInitializer = $object->__getInitializer();
        $object->__setInitializer(null);

        parent::setValue($object, $value);

        $object->__setInitializer($originalInitializer);
    }
}