getDeclaringClass() public static method

Returns declaring class or trait.
public static getDeclaringClass ( ReflectionProperty $prop ) : ReflectionClass
$prop ReflectionProperty
return ReflectionClass
Example #1
0
 private function resolveAnnotationClass(\Reflector $prop, $annotationValue, $annotationName)
 {
     /** @var Property|Method $prop */
     if (!($type = ltrim($annotationValue, '\\'))) {
         throw new InvalidStateException("Missing annotation @{$annotationName} with typehint on {$prop}.", $prop);
     }
     if (!class_exists($type) && !interface_exists($type)) {
         if (substr(func_get_arg(1), 0, 1) === '\\') {
             throw new MissingClassException("Class \"{$type}\" was not found, please check the typehint on {$prop} in annotation @{$annotationName}.", $prop);
         }
         $expandedType = NULL;
         if (method_exists('Nette\\Reflection\\AnnotationsParser', 'expandClassName')) {
             $expandedType = Nette\Reflection\AnnotationsParser::expandClassName($annotationValue, $prop instanceof \ReflectionProperty ? Nette\Reflection\Helpers::getDeclaringClass($prop) : $prop->getDeclaringClass());
         }
         if ($expandedType && (class_exists($expandedType) || interface_exists($expandedType))) {
             $type = $expandedType;
         } elseif (!class_exists($type = $prop->getDeclaringClass()->getNamespaceName() . '\\' . $type) && !interface_exists($type)) {
             throw new MissingClassException("Neither class \"" . func_get_arg(1) . "\" or \"{$type}\" was found, please check the typehint on {$prop} in annotation @{$annotationName}.", $prop);
         }
     }
     return ClassType::from($type)->getName();
 }