Returns declaring class or trait.
public static getDeclaringClass ( ReflectionProperty $prop ) : ReflectionClass | ||
$prop | ReflectionProperty | |
Результат | ReflectionClass |
private static function mockInjectedProperties() { /** @var \ReflectionProperty $property */ foreach (self::$reflectedClass->getProperties() as $property) { if (Nette\DI\PhpReflection::parseAnnotation($property, 'inject') !== NULL || Nette\DI\PhpReflection::parseAnnotation($property, 'autowire') !== NULL) { if ($mockedParameterClass = Nette\DI\PhpReflection::parseAnnotation($property, 'var')) { $mockedParameterClass = Nette\DI\PhpReflection::expandClassName($mockedParameterClass, Nette\DI\PhpReflection::getDeclaringClass($property)); } self::setProperty($mockedParameterClass, $property); } } }
/** @internal */ private static function checkType($class, string $name, $type, $container) { $rc = PhpReflection::getDeclaringClass(new \ReflectionProperty($class, $name)); $fullname = $rc->getName() . '::$' . $name; if (!$type) { throw new Nette\InvalidStateException("Property {$fullname} has no @var annotation."); } elseif (!class_exists($type) && !interface_exists($type)) { throw new Nette\InvalidStateException("Class or interface '{$type}' used in @var annotation at {$fullname} not found. Check annotation and 'use' statements."); } elseif (!$container->getByType($type, FALSE)) { throw new Nette\InvalidStateException("Service of type {$type} used in @var annotation at {$fullname} not found. Did you register it in configuration file?"); } }
/** * Generates list of properties with annotation @inject. * @return array */ public static function getInjectProperties(\ReflectionClass $class, $container = NULL) { $res = array(); foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { $type = PhpReflection::parseAnnotation($property, 'var'); if (PhpReflection::parseAnnotation($property, 'inject') === NULL) { continue; } elseif (!$type) { throw new Nette\InvalidStateException("Property {$property} has no @var annotation."); } $type = PhpReflection::expandClassName($type, PhpReflection::getDeclaringClass($property)); if (!class_exists($type) && !interface_exists($type)) { throw new Nette\InvalidStateException("Class or interface '{$type}' used in @var annotation at {$property} not found. Check annotation and 'use' statements."); } elseif ($container && !$container->getByType($type, FALSE)) { throw new ServiceCreationException("Service of type {$type} used in @var annotation at {$property} not found. Did you register it in configuration file?"); } $res[$property->getName()] = $type; } return $res; }