Exemple #1
0
 public function __construct($configEnvironment = NULL, $configFilePath = NULL, $autoStart = FALSE)
 {
     Saf_Kickstart::go();
     try {
         $this->_config = Saf_Config::load(!is_null($configFilePath) ? $configFilePath : APPLICATION_CONF, !is_null($configEnvironment) ? $configEnvironment : APPLICATION_ENV);
     } catch (Saf_Config_Exception_InvalidEnv $e) {
         Saf_Debug::out("Requested configutation section \"{$configEnvironment}\" not found, trying default...");
         $this->_config = Saf_Config::load($configFilePath, 'default');
     }
     $this->_autoLoad = $this->_config->getOptional('autoLoad', FALSE);
     $this->_debugMode = $this->_config->getOptional('debug:mode', Saf_Debug::DEBUG_MODE_OFF);
     $this->_errorMode = $this->_config->getOptional('error:mode', Saf_Debug::ERROR_MODE_INTERNAL);
     Saf_Debug::init($this->_debugMode, $this->_errorMode, FALSE);
     Saf_Kickstart::initializeAutoloader($this->_autoLoad);
     //#TODO #2.0.0 bootstrap config
     //#TODO #2.0.0 init plugins
     // loggingf
     // db
     // etc.
     if ($this->_config->has('plugins')) {
         foreach ($this->_config->get('plugins:+') as $pluginName => $pluginConfig) {
         }
         print_r(array('plugins', gettype($this->_config->get('plugins:+')), $this->_config->get('plugins:+')));
         print_r(array('plugins2', gettype($this->_config->get('plugins2:+')), $this->_config->get('plugins2')));
     }
     /*
      foreach() {
      
      }
      * 
      if(
      		'install' == APPLICATION_STATUS
      		&& !array_key_exists('install', $_REQUEST)
      ) {
     $e = new Exception('This application is Install Mode and currently unavailable.');
     Saf_Status::set(Saf_Status::STATUS_503_UNAVAILABLE);
     Saf_Kickstart::exceptionDisplay($e);
     }
     
     if('down' == APPLICATION_STATUS) {
     $e = new Exception('This application is in Maintenance Mode and currently unavailable.');
     Saf_Status::set(Saf_Status::STATUS_503_UNAVAILABLE);
     Saf_Kickstart::exceptionDisplay($e);
     }
     */
     if ($autoStart) {
         $this->start($autoStart);
     }
 }
Exemple #2
0
 /**
  * Starts the kickstart process, preparing the environment for a framework matching $mode
  * @param string $mode Any of the class's MODE_ constants
  * @return string the mode chosen (useful in the case of default MODE_AUTODETECT)
  */
 public static function go($mode = self::MODE_AUTODETECT)
 {
     if (!self::$_kicked) {
         defined('APPLICATION_START_TIME') || define('APPLICATION_START_TIME', microtime(TRUE));
         Saf_Kickstart::defineLoad('PUBLIC_PATH', realpath('.'));
         Saf_Kickstart::defineLoad('INSTALL_PATH', realpath('..'));
         Saf_Kickstart::defineLoad('LIBRARY_PATH', realpath(__DIR__));
         Saf_Kickstart::defineLoad('APPLICATION_PATH', realpath(INSTALL_PATH . '/application'));
         Saf_Kickstart::defineLoad('APPLICATION_ENV', 'production');
         Saf_Kickstart::defineLoad('APPLICATION_ID', '');
         if ('' == APPLICATION_PATH || '' == realpath(APPLICATION_PATH . '/configs') || !is_readable(APPLICATION_PATH)) {
             header('HTTP/1.0 500 Internal Server Error');
             die('Unable to find the application core.');
         }
         if ($mode == self::MODE_AUTODETECT) {
             $mode = self::_goAutoMode();
         }
         switch ($mode) {
             case self::MODE_ZFMVC:
                 $configFile = 'zend_application';
                 break;
             case self::MODE_SAF:
                 if (defined('APPLICATION_ID') && APPLICATION_ID) {
                     $applicationFilePart = strtolower(APPLICATION_ID);
                     //#TODO #1.0.0 filter file names safely
                     $configFile = "saf_application.{$applicationFilePart}";
                     if (file_exists(APPLICATION_PATH . "/configs/{$configFile}.xml")) {
                         break;
                     }
                 }
                 $configFile = 'saf_application';
                 break;
             default:
                 $configFile = 'application';
                 break;
         }
         Saf_Kickstart::defineLoad('APPLICATION_CONFIG', APPLICATION_PATH . "/configs/{$configFile}.xml");
         Saf_Kickstart::defineLoad('APPLICATION_STATUS', 'online');
         Saf_Kickstart::defineLoad('APPLICATION_BASE_ERROR_MESSAGE', 'Please inform your technical support staff.');
         Saf_Kickstart::defineLoad('APPLICATION_DEBUG_NOTIFICATION', 'Debug information available.');
         self::_goPreRoute();
         Saf_Kickstart::defineLoad('APPLICATION_FORCE_DEBUG', FALSE, Saf_Kickstart::CAST_BOOL);
         if (APPLICATION_FORCE_DEBUG) {
             Saf_Debug::init(Saf_Debug::DEBUG_MODE_FORCE, NULL, FALSE);
         }
         if ($mode == self::MODE_ZFMVC || $mode == self::MODE_ZFNONE) {
             self::_goZend();
         }
         if ($mode == self::MODE_SAF) {
             self::_goSaf();
         }
         self::_goPreBoot();
         self::$_kicked = $mode;
     }
     return self::$_kicked;
 }
Exemple #3
0
 protected function _applyConfig()
 {
     //#TODO #2.0.0 loop through the tags instead
     $autoLoad = $this->_config->getOptional('autoLoad', FALSE);
     $debugMode = $this->_config->getOptional('debug:mode', Saf_Debug::DEBUG_MODE_OFF);
     $errorMode = $this->_config->getOptional('error:mode', Saf_Debug::ERROR_MODE_DEFAULT);
     Saf_Debug::init($debugMode, $errorMode, FALSE);
     if ($autoLoad) {
         $autoLoadTakeover = array_key_exists('takeover', $autoLoad) && Saf_Filter_Truthy::filter($autoLoad['takeover']);
         Saf_Kickstart::initializeAutoloader($autoLoad);
         if (array_key_exists('loader', $autoLoad)) {
             $loaders = Saf_Config::autoGroup($autoLoad['loader']);
             foreach ($loaders as $loader) {
                 $loaderParts = explode(':', Saf_Filter_ConfigString($loader), 2);
                 !array_key_exists(1, $loaderParts) ? Saf_Kickstart::addAutoloader($loaderParts[0]) : Saf_Kickstart::addAutoloader($loaderParts[0], $loaderParts[1]);
             }
         }
         if (array_key_exists('library', $autoLoad)) {
             $libraries = Saf_Config::autoGroup($autoLoad['library']);
             foreach ($libraries as $library) {
                 $libParts = explode(':', Saf_Filter_ConfigString($library), 2);
                 !array_key_exists(1, $libParts) ? Saf_Kickstart::addLibrary($libParts[0]) : Saf_Kickstart::addLibrary(array($libParts[0], $libParts[1]));
             }
         }
         if (array_key_exists('special', $autoLoad)) {
             $specialLoaders = Saf_Config::autoGroup($autoLoad['special']);
             foreach ($specialLoaders as $special) {
                 $specialParts = explode(':', Saf_Filter_ConfigString($special), 2);
                 !array_key_exists(1, $specialParts) ? Saf_Kickstart::addLibrary(array($specialParts[0])) : Saf_Kickstart::addLibrary(array($specialParts[0], $specialParts[1]));
             }
         }
     }
     $this->_bootstrapConfig = $this->_config->getOptional('bootstrap', NULL);
     if ($this->_config->has('resources')) {
         $resources = Saf_Array::coerce($this->_config->get('resources:+'), Saf_Array::MODE_TRUNCATE);
         foreach ($resources as $pluginName => $pluginConfig) {
             $this->provision($pluginName, $pluginConfig);
         }
     }
 }