Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 1... Zeile 1...
1
<?php
1
<?php
Zeile -... Zeile 2...
-
 
2
 
-
 
3
declare(strict_types=1);
2
 
4
 
Zeile 3... Zeile 5...
3
namespace Doctrine\Instantiator;
5
namespace Doctrine\Instantiator;
4
 
6
 
5
use ArrayIterator;
7
use ArrayIterator;
Zeile 18... Zeile 20...
18
use function set_error_handler;
20
use function set_error_handler;
19
use function sprintf;
21
use function sprintf;
20
use function strlen;
22
use function strlen;
21
use function unserialize;
23
use function unserialize;
Zeile 22... Zeile -...
22
 
-
 
23
use const PHP_VERSION_ID;
-
 
24
 
24
 
25
final class Instantiator implements InstantiatorInterface
25
final class Instantiator implements InstantiatorInterface
26
{
26
{
27
    /**
27
    /**
28
     * Markers used internally by PHP to define whether {@see \unserialize} should invoke
28
     * Markers used internally by PHP to define whether {@see \unserialize} should invoke
29
     * the method {@see \Serializable::unserialize()} when dealing with classes implementing
29
     * the method {@see \Serializable::unserialize()} when dealing with classes implementing
30
     * the {@see \Serializable} interface.
30
     * the {@see \Serializable} interface.
31
     *
31
     *
32
     * @deprecated This constant will be private in 2.0
32
     * @deprecated This constant will be private in 2.0
33
     */
33
     */
34
    public const SERIALIZATION_FORMAT_USE_UNSERIALIZER = 'C';
-
 
35
 
-
 
36
    /** @deprecated This constant will be private in 2.0 */
34
    private const SERIALIZATION_FORMAT_USE_UNSERIALIZER   = 'C';
Zeile 37... Zeile 35...
37
    public const SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O';
35
    private const SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O';
38
 
36
 
39
    /**
37
    /**
40
     * Used to instantiate specific classes, indexed by class name.
38
     * Used to instantiate specific classes, indexed by class name.
41
     *
39
     *
42
     * @var callable[]
40
     * @var callable[]
Zeile 43... Zeile 41...
43
     */
41
     */
44
    private static $cachedInstantiators = [];
42
    private static array $cachedInstantiators = [];
45
 
43
 
46
    /**
44
    /**
47
     * Array of objects that can directly be cloned, indexed by class name.
45
     * Array of objects that can directly be cloned, indexed by class name.
48
     *
46
     *
Zeile 49... Zeile 47...
49
     * @var object[]
47
     * @var object[]
50
     */
-
 
51
    private static $cachedCloneables = [];
48
     */
52
 
49
    private static array $cachedCloneables = [];
53
    /**
-
 
54
     * @param string $className
50
 
55
     * @phpstan-param class-string<T> $className
51
    /**
56
     *
52
     * @phpstan-param class-string<T> $className
57
     * @return object
53
     *
58
     * @phpstan-return T
54
     * @phpstan-return T
59
     *
55
     *
60
     * @throws ExceptionInterface
56
     * @throws ExceptionInterface
61
     *
57
     *
62
     * @template T of object
58
     * @template T of object
63
     */
59
     */
64
    public function instantiate($className)
60
    public function instantiate(string $className): object
Zeile 82... Zeile 78...
82
    /**
78
    /**
83
     * Builds the requested object and caches it in static properties for performance
79
     * Builds the requested object and caches it in static properties for performance
84
     *
80
     *
85
     * @phpstan-param class-string<T> $className
81
     * @phpstan-param class-string<T> $className
86
     *
82
     *
87
     * @return object
-
 
88
     * @phpstan-return T
83
     * @phpstan-return T
89
     *
84
     *
90
     * @template T of object
85
     * @template T of object
91
     */
86
     */
92
    private function buildAndCacheFromFactory(string $className)
87
    private function buildAndCacheFromFactory(string $className): object
93
    {
88
    {
94
        $factory  = self::$cachedInstantiators[$className] = $this->buildFactory($className);
89
        $factory  = self::$cachedInstantiators[$className] = $this->buildFactory($className);
95
        $instance = $factory();
90
        $instance = $factory();
Zeile 96... Zeile 91...
96
 
91
 
Zeile 125... Zeile 120...
125
 
120
 
126
        $serializedString = sprintf(
121
        $serializedString = sprintf(
127
            '%s:%d:"%s":0:{}',
122
            '%s:%d:"%s":0:{}',
128
            is_subclass_of($className, Serializable::class) ? self::SERIALIZATION_FORMAT_USE_UNSERIALIZER : self::SERIALIZATION_FORMAT_AVOID_UNSERIALIZER,
123
            is_subclass_of($className, Serializable::class) ? self::SERIALIZATION_FORMAT_USE_UNSERIALIZER : self::SERIALIZATION_FORMAT_AVOID_UNSERIALIZER,
129
            strlen($className),
124
            strlen($className),
130
            $className
125
            $className,
Zeile 131... Zeile 126...
131
        );
126
        );
Zeile 132... Zeile 127...
132
 
127
 
133
        $this->checkIfUnSerializationIsSupported($reflectionClass, $serializedString);
-
 
134
 
-
 
135
        return static function () use ($serializedString) {
128
        $this->checkIfUnSerializationIsSupported($reflectionClass, $serializedString);
Zeile 136... Zeile 129...
136
            return unserialize($serializedString);
129
 
137
        };
130
        return static fn () => unserialize($serializedString);
138
    }
131
    }
Zeile 151... Zeile 144...
151
    {
144
    {
152
        if (! class_exists($className)) {
145
        if (! class_exists($className)) {
153
            throw InvalidArgumentException::fromNonExistingClass($className);
146
            throw InvalidArgumentException::fromNonExistingClass($className);
154
        }
147
        }
Zeile 155... Zeile 148...
155
 
148
 
156
        if (PHP_VERSION_ID >= 80100 && enum_exists($className, false)) {
149
        if (enum_exists($className, false)) {
157
            throw InvalidArgumentException::fromEnum($className);
150
            throw InvalidArgumentException::fromEnum($className);
Zeile 158... Zeile 151...
158
        }
151
        }
Zeile 179... Zeile 172...
179
            $error = UnexpectedValueException::fromUncleanUnSerialization(
172
            $error = UnexpectedValueException::fromUncleanUnSerialization(
180
                $reflectionClass,
173
                $reflectionClass,
181
                $message,
174
                $message,
182
                $code,
175
                $code,
183
                $file,
176
                $file,
184
                $line
177
                $line,
185
            );
178
            );
Zeile 186... Zeile 179...
186
 
179
 
187
            return true;
180
            return true;