/** * Initialisation function * @param $basePath */ protected function init($basePath = null) { // Configure the application (once) if ($this->configured == true) { return; } // TODO: Configure the base path if (empty($basePath)) { $this->basePath = dirname(__FILE__); } else { $this->basePath = (string) $basePath; } // TODO: Check for our servlet configuration files if (empty($this->configurationFiles)) { throw \Serphlet\Exception\UnavailableException('Missing servlet configuration. Please ensure application has added references to servlet configuration files (See Serphlet_Application::addServletConfigurationFile())'); } // self::setTimeMarker('INIT02 - Init Configuration'); // TODO: Process the servlet configuration if (self::configFileExpired()) { // Process the configuration $digester = new Serphlet_Phigester_Digester(); $digester->addRuleSet(new \Serphlet\Config\ApplicationRuleSet()); $this->context = new \Serphlet\Config\ApplicationContext($this->basePath, null); $digester->push($this->context); $configFilePath = self::getRealPath(current($this->configurationFiles)); $digester->parse($configFilePath); unset($digester); // Cache the config if (is_writable(self::getCacheDirectory())) { $cacheFile = self::getRealPath(self::getCacheDirectory() . DIRECTORY_SEPARATOR . 'serphlet.data'); $serialData = serialize($this->context); file_put_contents($cacheFile, $serialData); } } else { // Load the configuration $cacheFile = self::getRealPath(self::getCacheDirectory() . DIRECTORY_SEPARATOR . 'serphlet.data'); $serialData = file_get_contents($cacheFile); $this->context = unserialize($serialData); } // Configure connectors $this->request = new \Symfony\Component\HttpFoundation\Request(); $this->response = new \Symfony\Component\HttpFoundation\Response(); // Configure the base dir $this->request->setAttribute(\Serphlet\Globals::BASE_PATH, $basePath); // Complete initialisation $configured = true; }
public function addRuleInstances(Serphlet_Phigester_Digester $digester) { $digester->addSetProperties('web-app'); $digester->addCallMethod('web-app/include-paths/include-path', 'setIncludePath', 2); $digester->addCallParam('web-app/include-paths/include-path', 0, 'path'); $digester->addCallParam('web-app/include-paths/include-path', 1, 'context-relative'); $digester->addCallMethod('web-app/context-param', 'setInitParameter', 2); $digester->addCallParam('web-app/context-param/param-name', 0); $digester->addCallParam('web-app/context-param/param-value', 1); $digester->addFactoryCreate('web-app/error-page', new \Serphlet\Config\ErrorPageFactory()); $digester->addSetNext('web-app/error-page', 'addErrorPage'); $digester->addCallMethod('web-app/error-page/error-code', 'setErrorCode', 0); $digester->addCallMethod('web-app/error-page/exception-type', 'setExceptionType', 0); $digester->addCallMethod('web-app/error-page/location', 'setLocation', 0); $digester->addFactoryCreate('web-app/filter', new \Serphlet\Config\FilterDefFactory()); $digester->addSetNext('web-app/filter', 'addFilterDef'); $digester->addCallMethod('web-app/filter/description', 'setDescription', 0); $digester->addCallMethod('web-app/filter/display-name', 'setDisplayName', 0); $digester->addCallMethod('web-app/filter/filter-class', 'setFilterClass', 0); $digester->addCallMethod('web-app/filter/filter-name', 'setFilterName', 0); $digester->addCallMethod('web-app/filter/large-icon', 'setLargeIcon', 0); $digester->addCallMethod('web-app/filter/small-icon', 'setSmallIcon', 0); $digester->addCallMethod('web-app/filter/init-param', 'addInitParameter', 2); $digester->addCallParam('web-app/filter/init-param/param-name', 0); $digester->addCallParam('web-app/filter/init-param/param-value', 1); $digester->addFactoryCreate('web-app/filter-mapping', new \Serphlet\Config\FilterMapsFactory()); $digester->addSetNext('web-app/filter-mapping', 'addFilterMaps'); $digester->addCallMethod('web-app/filter-mapping/filter-name', 'setFilterName', 0); $digester->addCallMethod('web-app/filter-mapping/servlet-name', 'addServletName', 0); $digester->addCallMethod('web-app/filter-mapping/url-pattern', 'addURLPattern', 0); // TODO: // $digester->addCallMethod('web-app/filter-mapping/dispatcher', 'setDispatcher', 0); $digester->addFactoryCreate('web-app/servlet', new \Serphlet\Config\ApplicationConfigFactory()); $digester->addSetNext('web-app/servlet', 'addServletConfig'); $digester->addCallMethod('web-app/servlet/init-param', 'setInitParameter', 2); $digester->addCallParam('web-app/servlet/init-param/param-name', 0); $digester->addCallParam('web-app/servlet/init-param/param-value', 1); $digester->addCallMethod('web-app/servlet/servlet-name', 'setServletName', 0); $digester->addCallMethod('web-app/servlet/servlet-class', 'setServletClass', 0); $digester->addFactoryCreate('web-app/servlet-mapping', new \Serphlet\Config\ServletMapFactory()); $digester->addSetNext('web-app/servlet-mapping', 'addServletMapping'); $digester->addCallMethod('web-app/servlet-mapping/servlet-name', 'setServletName', 0); $digester->addCallMethod('web-app/servlet-mapping/url-pattern', 'addUrlPattern', 0); $digester->addCallMethod('web-app/welcome-file-list/welcome-file', 'addWelcomeFile', 0); }