AppserverIo\Appserver\ServletEngine\DependencyInjection\DeploymentDescriptorParser::injectServletContext PHP Метод

injectServletContext() публичный Метод

Inject the servlet context instance.
public injectServletContext ( AppserverIo\Psr\Servlet\ServletContextInterface $servletContext ) : void
$servletContext AppserverIo\Psr\Servlet\ServletContextInterface The servlet context instance
Результат void
    public function injectServletContext(ServletContextInterface $servletContext)
    {
        $this->servletContext = $servletContext;
    }

Usage Example

Пример #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);
         }
     }
 }