/** * Initializes the servlet descriptor instance from the passed reflection class instance. * * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the servlet description * * @return \AppserverIo\Psr\EnterpriseBeans\Description\ServletDescriptorInterface|null The initialized descriptor instance */ public function fromReflectionClass(ClassInterface $reflectionClass) { // query if we've a servlet if ($reflectionClass->implementsInterface('AppserverIo\\Psr\\Servlet\\ServletInterface') === false) { // if not, do nothing return; } // query if we've an interface or an abstract class if ($reflectionClass->toPhpReflectionClass()->isInterface() || $reflectionClass->toPhpReflectionClass()->isAbstract()) { // if so, do nothing return; } // set the servlet name $this->setName(lcfirst($reflectionClass->getShortName())); // set the class name $this->setClassName($reflectionClass->getName()); // query if we've a servlet with a @Route annotation if ($reflectionClass->hasAnnotation(Route::ANNOTATION)) { // create a new annotation instance $reflectionAnnotation = $this->newAnnotationInstance($reflectionClass); // initialize the annotation instance $annotationInstance = $reflectionAnnotation->newInstance($reflectionAnnotation->getAnnotationName(), $reflectionAnnotation->getValues()); // load the default name to register in naming directory if ($nameAttribute = $annotationInstance->getName()) { $this->setName($nameAttribute); } // register the servlet description defined as @Route(description=****) if ($description = $annotationInstance->getDescription()) { $this->setDescription($description); } // register the servlet display name defined as @Route(displayName=****) if ($displayName = $annotationInstance->getDisplayName()) { $this->setDisplayName($displayName); } // register the init params defined as @Route(initParams=****) foreach ($annotationInstance->getInitParams() as $initParam) { list($paramName, $paramValue) = $initParam; $this->addInitParam($paramName, $paramValue); } // register the URL pattern defined as @Route(urlPattern=****) foreach ($annotationInstance->getUrlPattern() as $urlPattern) { $this->addUrlPattern($urlPattern); } } // initialize references from the passed reflection class $this->referencesFromReflectionClass($reflectionClass); // return the instance return $this; }
/** * Adds the passe reflection class instance to the DI provider. * * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class instance to add * * @return void */ public function setReflectionClass(ClassInterface $reflectionClass) { $this->reflectionClasses[$reflectionClass->getName()] = $reflectionClass; }