AppserverIo\Appserver\ServletEngine\DependencyInjection\DirectoryParser::parse PHP Method

parse() public method

Parses the servlet context's web application base directory for servlets that has to be registered in the object manager.
public parse ( ) : void
return void
    public function parse()
    {
        // load the web application base directory
        $webappPath = $this->getServletContext()->getWebappPath();
        // load the directories to be parsed
        $directories = array();
        // append the directory found in the servlet managers configuration
        /** @var \AppserverIo\Appserver\Core\Api\Node\DirectoryNode $directoryNode */
        foreach ($this->getServletContext()->getDirectories() as $directoryNode) {
            // prepare the custom directory defined in the servlet managers configuration
            $customDir = $webappPath . DIRECTORY_SEPARATOR . ltrim($directoryNode->getNodeValue()->getValue(), DIRECTORY_SEPARATOR);
            // check if the directory exists
            if (is_dir($customDir)) {
                $directories[] = $customDir;
            }
        }
        // parse the directories for annotated servlets
        foreach ($directories as $directory) {
            $this->parseDirectory($directory);
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Finds all servlets which are provided by the webapps and initializes them.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  *
  * @throws \AppserverIo\Appserver\ServletEngine\InvalidServletMappingException
  */
 public function registerServlets(ApplicationInterface $application)
 {
     // query whether or not the web application folder exists
     if (is_dir($this->getWebappPath()) === false) {
         return;
     }
     // initialize the directory parser and parse the web application's base directory for annotated servlets
     $directoryParser = new DirectoryParser();
     $directoryParser->injectServletContext($this);
     $directoryParser->parse();
     // initialize the deployment descriptor parser and parse the web application's deployment descriptor for servlets
     $deploymentDescriptorParser = new DeploymentDescriptorParser();
     $deploymentDescriptorParser->injectServletContext($this);
     $deploymentDescriptorParser->parse();
     // load the object manager instance
     /** @var \AppserverIo\Appserver\DependencyInjectionContainer\Interfaces\ObjectManagerInterface $objectManager */
     $objectManager = $this->getApplication()->search('ObjectManagerInterface');
     // register the beans located by annotations and the XML configuration
     /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
     foreach ($objectManager->getObjectDescriptors() as $descriptor) {
         // check if we've found a servlet descriptor and register the servlet
         if ($descriptor instanceof ServletDescriptorInterface) {
             $this->registerServlet($descriptor);
         }
     }
 }