/**
  * Reads the @Request and @Response annotations.
  *
  * @param ConfigureRouteEvent $event
  */
 public function onConfigureRoute(ConfigureRouteEvent $event)
 {
     foreach (['_request' => 'Request', '_response' => 'Response'] as $name => $class) {
         if ($annotation = $this->getAnnotation($event->getMethod(), $class)) {
             if ($data = $annotation->getData()) {
                 $event->getRoute()->setDefault($name, $data);
             }
         }
     }
 }
示例#2
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));
     }
 }