function Registry::getClassReflector
5 calls to Registry::getClassReflector()
- Exporter::getArrayObjectProperties in vendor/
symfony/ var-exporter/ Internal/ Exporter.php - Exporter::prepare in vendor/
symfony/ var-exporter/ Internal/ Exporter.php - Prepares an array of values for VarExporter.
- Instantiator::instantiate in vendor/
symfony/ var-exporter/ Instantiator.php - Creates an object and sets its properties without calling its constructor nor any other methods.
- Registry::f in vendor/
symfony/ var-exporter/ Internal/ Registry.php - Registry::p in vendor/
symfony/ var-exporter/ Internal/ Registry.php
File
-
vendor/
symfony/ var-exporter/ Internal/ Registry.php, line 64
Class
- Registry
- @author Nicolas Grekas <p@tchwork.com>
Namespace
Symfony\Component\VarExporter\InternalCode
public static function getClassReflector($class, $instantiableWithoutConstructor = false, $cloneable = null) {
if (!($isClass = class_exists($class)) && !interface_exists($class, false) && !trait_exists($class, false)) {
throw new ClassNotFoundException($class);
}
$reflector = new \ReflectionClass($class);
if ($instantiableWithoutConstructor) {
$proto = $reflector->newInstanceWithoutConstructor();
}
elseif (!$isClass || $reflector->isAbstract()) {
throw new NotInstantiableTypeException($class);
}
elseif ($reflector->name !== $class) {
$reflector = self::$reflectors[$name = $reflector->name] ??= self::getClassReflector($name, false, $cloneable);
self::$cloneable[$class] = self::$cloneable[$name];
self::$instantiableWithoutConstructor[$class] = self::$instantiableWithoutConstructor[$name];
self::$prototypes[$class] = self::$prototypes[$name];
return $reflector;
}
else {
try {
$proto = $reflector->newInstanceWithoutConstructor();
$instantiableWithoutConstructor = true;
} catch (\ReflectionException) {
$proto = $reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize') ? 'C:' : 'O:';
if ('C:' === $proto && !$reflector->getMethod('unserialize')
->isInternal()) {
$proto = null;
}
else {
try {
$proto = @unserialize($proto . \strlen($class) . ':"' . $class . '":0:{}');
} catch (\Exception $e) {
if (__FILE__ !== $e->getFile()) {
throw $e;
}
throw new NotInstantiableTypeException($class, $e);
}
if (false === $proto) {
throw new NotInstantiableTypeException($class);
}
}
}
if (null !== $proto && !$proto instanceof \Throwable && !$proto instanceof \Serializable && !method_exists($class, '__sleep') && !method_exists($class, '__serialize')) {
try {
serialize($proto);
} catch (\Exception $e) {
throw new NotInstantiableTypeException($class, $e);
}
}
}
if (null === $cloneable) {
if (($proto instanceof \Reflector || $proto instanceof \ReflectionGenerator || $proto instanceof \ReflectionType || $proto instanceof \IteratorIterator || $proto instanceof \RecursiveIteratorIterator) && (!$proto instanceof \Serializable && !method_exists($proto, '__wakeup') && !method_exists($class, '__unserialize'))) {
throw new NotInstantiableTypeException($class);
}
$cloneable = $reflector->isCloneable() && !$reflector->hasMethod('__clone');
}
self::$cloneable[$class] = $cloneable;
self::$instantiableWithoutConstructor[$class] = $instantiableWithoutConstructor;
self::$prototypes[$class] = $proto;
if ($proto instanceof \Throwable) {
static $setTrace;
if (null === $setTrace) {
$setTrace = [
new \ReflectionProperty(\Error::class, 'trace'),
new \ReflectionProperty(\Exception::class, 'trace'),
];
$setTrace[0] = $setTrace[0]->setValue(...);
$setTrace[1] = $setTrace[1]->setValue(...);
}
$setTrace[$proto instanceof \Exception]($proto, []);
}
return $reflector;
}