/** * Reads the "@Access" annotations from the controller stores them in the "access" route option. */ public function onConfigureRoute($event, $route) { if (!$this->reader) { $this->reader = new SimpleAnnotationReader(); $this->reader->addNamespace('Pagekit\\User\\Annotation'); } if (!$route->getControllerClass()) { return; } $access = []; foreach (array_merge($this->reader->getClassAnnotations($route->getControllerClass()), $this->reader->getMethodAnnotations($route->getControllerMethod())) as $annot) { if (!$annot instanceof Access) { continue; } if ($expression = $annot->getExpression()) { $access[] = $expression; } if ($admin = $annot->getAdmin() !== null) { $route->setPath('admin' . rtrim($route->getPath(), '/')); $permission = 'system: access admin area'; if ($admin) { $access[] = $permission; } else { if ($key = array_search($permission, $access)) { unset($access[$key]); } } } } if ($access) { $route->setDefault('_access', array_unique($access)); } }
protected function setUp() { AnnotationRegistry::registerLoader('class_exists'); $this->reader = new SimpleAnnotationReader(); $this->reader->addNamespace('Bazinga\\Bundle\\GeocoderBundle\\Mapping\\Annotations'); $this->driver = new AnnotationDriver($this->reader); }
/** * Gets the used doctrine annotation reader. * * @return \Doctrine\Common\Annotations\Reader * The annotation reader. */ protected function getAnnotationReader() { if (!isset($this->annotationReader)) { $this->annotationReader = new SimpleAnnotationReader(); // Add the namespaces from the main plugin annotation, like @EntityType. $namespace = substr($this->pluginDefinitionAnnotationName, 0, strrpos($this->pluginDefinitionAnnotationName, '\\')); $this->annotationReader->addNamespace($namespace); } return $this->annotationReader; }
/** * Get the annotation reader instance. * * @return Reader */ protected function getAnnotationReader() { if (!$this->reader) { $this->reader = new SimpleAnnotationReader(); $this->reader->addNamespace('Pagekit\\Routing\\Annotation'); } return $this->reader; }
/** * @return Reader The annotation reader */ public function getAnnotationReader() { if ($this->annotationReader == null) { AnnotationRegistry::registerAutoloadNamespace('DI\\Annotation', __DIR__ . '/../../../'); $this->annotationReader = new SimpleAnnotationReader(); $this->annotationReader->addNamespace('DI\\Annotation'); } return $this->annotationReader; }
/** * Reads the "@Access" annotations from the controller stores them in the "access" route option. * * @param ConfigureRouteEvent $event */ public function onConfigureRoute(ConfigureRouteEvent $event) { if (!$this->reader) { $this->reader = new SimpleAnnotationReader(); $this->reader->addNamespace('Pagekit\\User\\Annotation'); } $admin = false; $access = []; foreach ($this->reader->getClassAnnotations($event->getClass()) as $annot) { if ($annot instanceof Access) { if ($expression = $annot->getExpression()) { $access[] = $expression; } if ($annot->getAdmin()) { $admin = true; } } } foreach ($this->reader->getMethodAnnotations($event->getMethod()) as $annot) { if ($annot instanceof Access) { if ($expression = $annot->getExpression()) { $access[] = $expression; } if ($annot->getAdmin()) { $admin = true; } } } $route = $event->getRoute(); if ($admin) { $route->setPath(rtrim('admin' . $route->getPath(), '/')); $access[] = 'system: access admin area'; } if ($access) { $route->setDefault('_access', array_unique($access)); } }