Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\LazyProxy; Chris@14: Chris@14: /** Chris@14: * @author Nicolas Grekas Chris@14: * Chris@14: * @internal Chris@14: */ Chris@14: class ProxyHelper Chris@14: { Chris@14: /** Chris@14: * @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context Chris@14: */ Chris@14: public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false) Chris@14: { Chris@14: if ($p instanceof \ReflectionParameter) { Chris@14: if (method_exists($p, 'getType')) { Chris@14: $type = $p->getType(); Chris@14: } elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $p, $type)) { Chris@14: $name = $type = $type[1]; Chris@14: Chris@14: if ('callable' === $name || 'array' === $name) { Chris@14: return $noBuiltin ? null : $name; Chris@14: } Chris@14: } Chris@14: } else { Chris@14: $type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null; Chris@14: } Chris@14: if (!$type) { Chris@14: return; Chris@14: } Chris@17: if (!\is_string($type)) { Chris@14: $name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString(); Chris@14: Chris@14: if ($type->isBuiltin()) { Chris@14: return $noBuiltin ? null : $name; Chris@14: } Chris@14: } Chris@14: $lcName = strtolower($name); Chris@14: $prefix = $noBuiltin ? '' : '\\'; Chris@14: Chris@14: if ('self' !== $lcName && 'parent' !== $lcName) { Chris@14: return $prefix.$name; Chris@14: } Chris@14: if (!$r instanceof \ReflectionMethod) { Chris@14: return; Chris@14: } Chris@14: if ('self' === $lcName) { Chris@14: return $prefix.$r->getDeclaringClass()->name; Chris@14: } Chris@14: if ($parent = $r->getDeclaringClass()->getParentClass()) { Chris@14: return $prefix.$parent->name; Chris@14: } Chris@14: } Chris@14: }