/** * Creates and initializes a beans reference configuration instance from the passed * reflection method instance. * * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans reference configuration * * @return \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionMethod(MethodInterface $reflectionMethod) { // if we found a @EnterpriseBean annotation, load the annotation instance if ($reflectionMethod->hasAnnotation(EnterpriseBean::ANNOTATION) === false) { // if not, do nothing return; } // initialize the annotation instance $annotation = $reflectionMethod->getAnnotation(EnterpriseBean::ANNOTATION); // load the annotation instance $annotationInstance = $annotation->newInstance($annotation->getAnnotationName(), $annotation->getValues()); // load the reference name defined as @EnterpriseBean(name=****) if ($name = $annotationInstance->getName()) { $this->setName(sprintf('%s/%s', EpbReferenceDescriptor::REF_DIRECTORY, $name)); } else { // use the name of the first parameter as local business interface foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $this->setName(sprintf('%s/%s', EpbReferenceDescriptor::REF_DIRECTORY, ucfirst($reflectionParameter->getParameterName()))); break; } } // register the bean with the name defined as @EnterpriseBean(beanName=****) if ($beanNameAttribute = $annotationInstance->getBeanName()) { $this->setBeanName($beanNameAttribute); } else { $this->setBeanName(ucfirst(str_replace(EpbReferenceDescriptor::REF_DIRECTORY . '/', '', $this->getName()))); } // register the bean with the interface defined as @EnterpriseBean(beanInterface=****) if ($beanInterfaceAttribute = $annotationInstance->getBeanInterface()) { $this->setBeanInterface($beanInterfaceAttribute); } else { $this->setBeanInterface(sprintf('%sLocal', ucfirst($this->getBeanName()))); } // register the bean with the lookup name defined as @EnterpriseBean(lookup=****) if ($lookupAttribute = $annotationInstance->getLookup()) { $this->setLookup($lookupAttribute); } // register the bean with the interface defined as @EnterpriseBean(description=****) if ($descriptionAttribute = $annotationInstance->getDescription()) { $this->setDescription($descriptionAttribute); } // load the injection target data $this->setInjectionTarget(InjectionTargetDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)); // return the instance return $this; }
/** * Creates and initializes a beans reference configuration instance from the passed * reflection method instance. * * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans reference configuration * * @return \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionMethod(MethodInterface $reflectionMethod) { // if we found a @Resource annotation, load the annotation instance if ($reflectionMethod->hasAnnotation(Resource::ANNOTATION) === false) { // if not, do nothing return; } // initialize the annotation instance $annotation = $reflectionMethod->getAnnotation(Resource::ANNOTATION); // load the annotation instance $annotationInstance = $annotation->newInstance($annotation->getAnnotationName(), $annotation->getValues()); // load the reference name defined as @Resource(name=****) if ($name = $annotationInstance->getName()) { $this->setName(sprintf('%s/%s', ResReferenceDescriptor::REF_DIRECTORY, $name)); } else { // use the name of the first parameter foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $this->setName(sprintf('%s/%s', ResReferenceDescriptor::REF_DIRECTORY, ucfirst($reflectionParameter->getParameterName()))); break; } } // load the resource type defined as @Resource(type=****) if ($type = $annotationInstance->getType()) { $this->setType($type); } else { // use the name of the first parameter as local business interface foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $this->setType(ucfirst($reflectionParameter->getParameterName())); break; } } // load the lookup defined as @Resource(lookup=****) if ($lookup = $annotationInstance->getLookup()) { $this->setLookup($lookup); } // load the resource description defined as @Resource(description=****) if ($description = $annotationInstance->getDescription()) { $this->setDescription($description); } // load the injection target data $this->setInjectionTarget(InjectionTargetDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)); // return the instance return $this; }
/** * Creates and initializes a beans reference configuration instance from the passed * reflection method instance. * * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans reference configuration * * @return \AppserverIo\Psr\EnterpriseBeans\Description\PersistenceUnitReferenceDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionMethod(MethodInterface $reflectionMethod) { // if we found a @PersistenceUnit annotation, load the annotation instance if ($reflectionMethod->hasAnnotation(PersistenceUnit::ANNOTATION) === false) { // if not, do nothing return; } // initialize the annotation instance $annotation = $reflectionMethod->getAnnotation(PersistenceUnit::ANNOTATION); // load the annotation instance $annotationInstance = $annotation->newInstance($annotation->getAnnotationName(), $annotation->getValues()); // load the reference name defined as @PersistenceUnit(name=****) if ($name = $annotationInstance->getName()) { $this->setName(sprintf('%s/%s', PersistenceUnitReferenceDescriptor::REF_DIRECTORY, $name)); } else { // use the name of the first parameter foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $this->setName(sprintf('%s/%s', PersistenceUnitReferenceDescriptor::REF_DIRECTORY, ucfirst($reflectionParameter->getParameterName()))); break; } } // load the resource type defined as @PersistenceUnit(unitName=****) if ($unitName = $annotationInstance->getUnitName()) { $this->setUnitName($unitName); } else { // use the name of the first parameter unit name foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $this->setUnitName(ucfirst($reflectionParameter->getParameterName())); break; } } // load the injection target data $this->setInjectionTarget(InjectionTargetDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)); // return the instance return $this; }
/** * 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; }