Пример #1
0
 /**
  * This test checks the resolved class name.
  *
  * @return void
  */
 public function testGetClass()
 {
     $this->assertSame('AppserverIo\\Routlt\\Annotations\\Action', $this->annotation->__getClass());
 }
Пример #2
0
 /**
  * Initializes the action configuration instance from the passed reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the action configuration
  *
  * @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor
  */
 public function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // add the annotation alias to the reflection method
     $reflectionMethod->addAnnotationAlias(Action::ANNOTATION, Action::__getClass());
     // query if we've a method with a @Action annotation
     if ($reflectionMethod->hasAnnotation(Action::ANNOTATION) === false && $reflectionMethod->getMethodName() !== 'perform') {
         // if not, do nothing
         return;
         // query whether we've the default perform() method WITHOUT an @Action annotation
     } elseif ($reflectionMethod->hasAnnotation(Action::ANNOTATION) === false && $reflectionMethod->getMethodName() === 'perform') {
         // create an annotation instance manually
         $reflectionAnnotation = new ReflectionAnnotation(Action::__getClass());
     } else {
         // create a new annotation instance by default
         $reflectionAnnotation = $this->newAnnotationInstance($reflectionMethod);
     }
     // load method name
     $this->setMethodName($reflectionMethod->getMethodName());
     // initialize the annotation instance
     $annotationInstance = $reflectionAnnotation->newInstance($reflectionAnnotation->getAnnotationName(), $reflectionAnnotation->getValues());
     // load the default name to register in naming directory
     if (($nameAttribute = $annotationInstance->getName()) || $nameAttribute === '') {
         $this->setName($nameAttribute);
     } else {
         // if @Annotation(name=****) is NOT SET, we use the method name by default
         $this->setName('/' . lcfirst(str_replace('Action', '', $reflectionMethod->getMethodName())));
     }
     // initialize the array for the annotated request methods
     $annotatedRequestMethods = array();
     // parse the method for annotated request methods
     foreach ($this->getRequestMethods() as $requestMethod) {
         // prepare the annotation name, e. g. POST -> Post
         $annotationName = ucfirst(strtolower($requestMethod));
         // query whether the reflection method has been annotated
         if ($reflectionMethod->hasAnnotation($annotationName)) {
             array_push($annotatedRequestMethods, $requestMethod);
         }
     }
     // query whether at least one annotated request method has been found
     if (sizeof($annotatedRequestMethods) > 0) {
         // if yes, override the default request methods
         $this->setRequestMethods($annotatedRequestMethods);
     }
     // initialize the restrictions for the route placeholders
     if (is_array($restrictions = $annotationInstance->getRestrictions())) {
         foreach ($restrictions as $restriction) {
             list($name, $value) = $restriction;
             $this->restrictions[$name] = $value;
         }
     }
     // initialize the defaults for the route placeholders
     if (is_array($defaults = $annotationInstance->getDefaults())) {
         foreach ($defaults as $default) {
             list($name, $value) = $default;
             $this->defaults[$name] = $value;
         }
     }
     // return the instance
     return $this;
 }