Пример #1
0
 /**
  * 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;
 }