1 | <?php |
||
33 | final class Instantiator |
||
34 | { |
||
35 | /** |
||
36 | * Markers used internally by PHP to define whether {@see \unserialize} should invoke |
||
37 | * the method {@see \Serializable::unserialize()} when dealing with classes implementing |
||
38 | * the {@see \Serializable} interface. |
||
39 | */ |
||
40 | const SERIALIZATION_FORMAT_USE_UNSERIALIZER = 'C'; |
||
41 | const SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O'; |
||
42 | |||
43 | /** |
||
44 | * {@inheritDoc} |
||
45 | */ |
||
46 | 402 | public function instantiate($className) |
|
54 | |||
55 | /** |
||
56 | * @internal |
||
57 | * @private |
||
58 | * |
||
59 | * Builds a {@see \Closure} capable of instantiating the given $className without |
||
60 | * invoking its constructor. |
||
61 | * This method is only exposed as public because of PHP 5.3 compatibility. Do not |
||
62 | * use this method in your own code |
||
63 | * |
||
64 | * @param string $className |
||
65 | * |
||
66 | * @return Closure |
||
67 | */ |
||
68 | 402 | public function buildFactory($className) |
|
91 | |||
92 | /** |
||
93 | * @param string $className |
||
94 | * |
||
95 | * @return ReflectionClass |
||
96 | * |
||
97 | * @throws InvalidArgumentException |
||
98 | */ |
||
99 | 402 | private function getReflectionClass($className) |
|
113 | |||
114 | /** |
||
115 | * @param ReflectionClass $reflectionClass |
||
116 | * @param string $serializedString |
||
117 | * |
||
118 | * @throws UnexpectedValueException |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | private function attemptInstantiationViaUnSerialization(ReflectionClass $reflectionClass, $serializedString) |
||
149 | |||
150 | /** |
||
151 | * @param ReflectionClass $reflectionClass |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | 402 | private function isInstantiableViaReflection(ReflectionClass $reflectionClass) |
|
159 | |||
160 | /** |
||
161 | * Verifies whether the given class is to be considered internal |
||
162 | * |
||
163 | * @param ReflectionClass $reflectionClass |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | private function hasInternalAncestors(ReflectionClass $reflectionClass) |
||
177 | |||
178 | /** |
||
179 | * Verifies if the given PHP version implements the `Serializable` interface serialization |
||
180 | * with an incompatible serialization format. If that's the case, use serialization marker |
||
181 | * "C" instead of "O". |
||
182 | * |
||
183 | * @link http://news.php.net/php.internals/74654 |
||
184 | * |
||
185 | * @param ReflectionClass $reflectionClass |
||
186 | * |
||
187 | * @return string the serialization format marker, either self::SERIALIZATION_FORMAT_USE_UNSERIALIZER |
||
188 | * or self::SERIALIZATION_FORMAT_AVOID_UNSERIALIZER |
||
189 | */ |
||
190 | private function getSerializationFormat(ReflectionClass $reflectionClass) |
||
200 | |||
201 | /** |
||
202 | * Checks whether the current PHP runtime uses an incompatible serialization format |
||
203 | * |
||
204 | * @return bool |
||
205 | */ |
||
206 | private function isPhpVersionWithBrokenSerializationFormat() |
||
210 | } |
||
211 |