Пример #1
0
 /**
  * @param ParseEvent $event
  */
 public function onClassParsed(ParseEvent $event)
 {
     $this->cacheControllers($event->getParam('config'));
     // handle class annotations
     $classHolder = $event->getTarget();
     $classAnnotationsCollection = $classHolder->getAnnotations();
     $classAnnotations = new AnnotationCollection();
     foreach ($classAnnotationsCollection as $annotation) {
         if (!$annotation instanceof Route) {
             continue;
         }
         $classAnnotations->append($annotation);
         $this->handleClassAnnotation($annotation, $classHolder->getClass());
     }
     // handle annotations per method
     foreach ($classHolder->getMethods() as $methodHolder) {
         foreach ($methodHolder->getAnnotations() as $methodAnnotation) {
             if (!$methodAnnotation instanceof Route) {
                 continue;
             }
             $this->handleMethodAnnotation($methodAnnotation, $classAnnotations, $classHolder->getClass(), $methodHolder->getMethod());
         }
     }
     $event->mergeResult(array('router' => array('routes' => $this->config)));
 }
 public function onClassParsed(ParseEvent $event)
 {
     $this->resolveControllers($event->getParam('config'));
     $classHolder = $event->getTarget();
     $methodHolders = $classHolder->getMethods();
     $config = [];
     foreach ($methodHolders as $methodHolder) {
         foreach ($methodHolder->getAnnotations() as $annotation) {
             $controller = $classHolder->getClass()->getName();
             if (isset($this->controllers[$controller])) {
                 $controller = $this->controllers[$controller];
             }
             $method = preg_replace('/Action$/', '', $methodHolder->getMethod()->getName());
             if ($annotation instanceof Asserts) {
                 foreach ($annotation->getNames() as $name) {
                     $options = empty($annotation->getOptions()[$name]) ? [] : $annotation->getOptions()[$name];
                     $config['asserts'][$controller][$method][] = ['assert' => $name, 'options' => $options];
                 }
             }
             if ($annotation instanceof Assert) {
                 $config['asserts'][$controller][$method][] = ['assert' => $annotation->getName(), 'options' => $annotation->getOptions()];
             }
         }
     }
     $event->mergeResult($config);
 }
 /**
  * 
  * @param ParseEvent $event
  */
 public function onFinalize(ParseEvent $event)
 {
     $config = $event->getTarget();
     array_walk_recursive($config, function (&$value, $key) use($config) {
         if (is_object($value)) {
             $value = $value($config);
         }
     });
     $event->setTarget($config);
 }
Пример #4
0
 /**
  * @param ParseEvent $event
  */
 public function onClassParsed(ParseEvent $event)
 {
     $classHolder = $event->getTarget();
     $classAnnotations = $classHolder->getAnnotations();
     foreach ($classAnnotations as $annotation) {
         if (!$annotation instanceof Service) {
             continue;
         }
         $this->handleClassAnnotation($annotation, $classHolder->getClass());
     }
     $event->mergeResult($this->definitions);
 }
 public function onClassParsed(ParseEvent $event)
 {
     $classHolder = $event->getTarget();
     $classAnnotations = $classHolder->getAnnotations();
     foreach ($classAnnotations as $annotation) {
         if ($annotation instanceof Toggle && !$this->isActive($annotation->getName())) {
             throw new \RuntimeException();
         }
     }
     $methodHolders = $classHolder->getMethods();
     foreach ($methodHolders as $methodHolder) {
         foreach ($methodHolder->getAnnotations() as $annotation) {
             if ($annotation instanceof Toggle && !$this->isActive($annotation->getName())) {
                 throw new \RuntimeException();
             }
         }
     }
 }
 public function onClassParsed(ParseEvent $event)
 {
     $this->resolveControllers($event->getParam('config'));
     $config = array();
     $classHolder = $event->getTarget();
     $controller = $classHolder->getClass()->getName();
     if (isset($this->controllers[$controller])) {
         $controller = $this->controllers[$controller];
     }
     foreach ($classHolder->getAnnotations() as $classAnnotation) {
         if ($classAnnotation instanceof Acl) {
             $allow = $classAnnotation->getAllow();
             $deny = $classAnnotation->getDeny();
             if ($allow) {
                 $config['acl']['resources']['allow'][$controller]['*'] = $allow;
             }
             if ($deny) {
                 $config['acl']['resources']['deny'][$controller]['*'] = $deny;
             }
         }
     }
     $methodHolders = $classHolder->getMethods();
     foreach ($methodHolders as $methodHolder) {
         foreach ($methodHolder->getAnnotations() as $annotation) {
             if ($annotation instanceof Acl) {
                 $method = preg_replace('/Action$/', '', $methodHolder->getMethod()->getName());
                 $allow = $annotation->getAllow();
                 $deny = $annotation->getDeny();
                 if ($allow) {
                     $config['acl']['resources']['allow'][$controller][$method] = $allow;
                 }
                 if ($deny) {
                     $config['acl']['resources']['deny'][$controller][$method] = $deny;
                 }
             }
         }
     }
     $event->mergeResult($config);
 }
 public function setUp()
 {
     $this->parseEvent = new ParseEvent();
     $this->parseEvent->setName('onClassParsed')->setTarget(new ClassAnnotationHolder(new ClassScanner([])));
     $this->listener = new ToggleListener();
 }