Пример #1
0
 /**
  * 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));
     }
 }