AppserverIo\Appserver\ServletEngine\ServletConfiguration::addInitParameter PHP Method

addInitParameter() public method

Register's the init parameter under the passed name.
public addInitParameter ( string $name, string $value ) : void
$name string Name to register the init parameter with
$value string The value of the init parameter
return void
    public function addInitParameter($name, $value)
    {
        $this->initParameter[$name] = $value;
    }

Usage Example

 /**
  * Register the servlet described by the passed descriptor.
  *
  * @param \AppserverIo\Psr\Servlet\Description\ServletDescriptorInterface $descriptor The servlet descriptor
  *
  * @return void
  */
 protected function registerServlet(ServletDescriptorInterface $descriptor)
 {
     try {
         // create a new reflection class instance
         $reflectionClass = new ReflectionClass($descriptor->getClassName());
         // instantiate the servlet
         $instance = $reflectionClass->newInstance();
         // load servlet name
         $servletName = $descriptor->getName();
         // initialize the servlet configuration
         $servletConfig = new ServletConfiguration();
         $servletConfig->injectServletContext($this);
         $servletConfig->injectServletName($servletName);
         // append the init params to the servlet configuration
         foreach ($descriptor->getInitParams() as $paramName => $paramValue) {
             $servletConfig->addInitParameter($paramName, $paramValue);
         }
         // initialize the servlet
         $instance->init($servletConfig);
         // the servlet is added to the dictionary using the complete request path as the key
         $this->addServlet($servletName, $instance);
         // prepend the url-pattern - servlet mapping to the servlet mappings
         foreach ($descriptor->getUrlPatterns() as $pattern) {
             $this->addServletMapping($pattern, $servletName);
         }
         // register the EPB references
         foreach ($descriptor->getEpbReferences() as $epbReference) {
             $this->registerEpbReference($epbReference);
         }
         // register the resource references
         foreach ($descriptor->getResReferences() as $resReference) {
             $this->registerResReference($resReference);
         }
         // register the persistence unit references
         foreach ($descriptor->getPersistenceUnitReferences() as $persistenceUnitReference) {
             $this->registerPersistenceUnitReference($persistenceUnitReference);
         }
     } catch (\Exception $e) {
         // log the exception
         $this->getApplication()->getInitialContext()->getSystemLogger()->critical($e->__toString());
     }
 }