Returns an annotation value.
public getAnnotation ( $name ) : Nette\Reflection\IAnnotation | ||
return | Nette\Reflection\IAnnotation |
/** * @return array */ protected function prepareRepositories() { $builder = $this->getContainerBuilder(); $repositories = []; foreach ($builder->findByType(Repository::class) as $repositoryName => $definition) { $repositoryClass = $definition->getClass(); $reflection = new ClassType($repositoryClass); $name = $reflection->getAnnotation('entity2'); if ($name === NULL) { $name = $this->createEntityName($repositoryClass); } $repositories[$name] = $repositoryClass; $mapperClass = Strings::replace($repositoryClass, '~Repository$~', 'Mapper'); $mapperName = $builder->getByType($mapperClass); if ($mapperName === NULL) { $mapperName = Strings::replace($repositoryName, '~Repository$~', 'Mapper'); $builder->addDefinition($mapperName)->setClass($mapperClass)->setArguments(['cache' => '@' . $this->prefix('cache')]); } else { $builder->getDefinition($mapperName)->setArguments(['cache' => '@' . $this->prefix('cache')]); } $definition->setArguments(['mapper' => '@' . $mapperName, 'dependencyProvider' => '@' . $this->prefix('dependencyProvider')]); $definition->addSetup('setModel', ['@' . $this->prefix('model')]); } return $repositories; }
/** * @param string * @param string * @return array */ public static function parseAnnotations($class, $method = NULL) { if (strpos($class, '::') !== FALSE && !$method) { list($class, $method) = explode('::', $class); } $ref = new Reflection\Method($class, $method); $cRef = new Reflection\ClassType($class); $anntations = (array)$ref->getAnnotation('allowed'); $role = isset($anntations['role']) ? $anntations['role'] : ($ref->hasAnnotation('role') ? $ref->getAnnotation('role') : NULL); $resource = isset($anntations['resource']) ? $anntations['resource'] : ($ref->hasAnnotation('resource') ? $ref->getAnnotation('resource') : ($cRef->hasAnnotation('resource') ? $cRef->getAnnotation('resource') : NULL)); $privilege = isset($anntations['privilege']) ? $anntations['privilege'] : ($ref->hasAnnotation('privilege') ? $ref->getAnnotation('privilege') : NULL); return array( static::ROLE => $role, static::RESOURCE => $resource, static::PRIVILEGE => $privilege, ); }
public function init() { if ($this->presenterMap !== NULL) { return; } $this->presenterMap = $this->nameMap = array(); foreach ($this->findClasses() as $className) { $class = new ClassType($className); $presenter = ltrim($class->getAnnotation('Presenter'), ':'); $name = $class->getAnnotation('Name'); if ($presenter) { $this->presenterMap[substr($presenter, -1) === ':' ? $presenter . 'default' : $presenter] = $className; } if ($name) { $this->nameMap[$className] = $name; } } }
private function walkClassHierarchy(ClassType $classType, &$expressions) { $parentClass = $classType->getParentClass(); if ($parentClass) { $this->walkClassHierarchy($parentClass, $expressions); } $annotation = $classType->getAnnotation('Security'); if ($annotation) { if (!is_string($annotation)) { throw new \InvalidArgumentException('Security annotation must be simple string with expression.'); } $expressions[] = new Expression($annotation); } }