예제 #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);
     }
 }
예제 #2
0
파일: Xml.php 프로젝트: jthurteau/saf
 public function parseResponse($rawResponseArray, $finalPattern = self::API_PARSE_PATTERN_NONE, $levelsDeep = 2)
 {
     if (is_null($finalPattern)) {
         $finalPattern = self::API_PARSE_PATTERN_NONE;
     }
     if (!array_key_exists('failedConnectionInfo', $rawResponseArray)) {
         if ($rawResponseArray['status'] > 200) {
             ob_start();
             print_r($rawResponseArray['failedConnectionInfo']);
             $rawFail = ob_get_contents();
             ob_end_clean();
             $prev = Saf_Debug::isEnabled() ? new Exception(htmlentities($rawFail)) : NULL;
             throw new Saf_Exception_BadGateway('The scheduling system failed. ', $rawResponseArray['status'], $prev);
         }
         $xmlResult = simplexml_load_string($rawResponseArray['raw'], 'SimpleXMLElement', 0, 'http://www.w3.org/2003/05/soap-envelope', FALSE);
         if ($xmlResult) {
             $envelope = $xmlResult->children('http://www.w3.org/2003/05/soap-envelope');
             $current = $envelope;
             for ($i = 0; $i < $levelsDeep; $i++) {
                 $current = $current->children();
             }
             $payloadXml = (string) $current;
             $data = simplexml_load_string($payloadXml);
             $parsedData = Saf_Config::arrayMap($data);
             if (is_array($parsedData) && array_key_exists('Error', $parsedData)) {
                 if (is_array($parsedData['Error']) && array_key_exists('Message', $parsedData['Error'])) {
                     $message = $parsedData['Error']['Message'];
                     $userMessage = Saf_Debug::isEnabled() ? $message : 'Server returned an error message that has been logged';
                     //#TODO #1.1.0 decide how to handle error logging
                     throw new Saf_Exception_Upstream($message, 0);
                 } else {
                     Saf_Debug::outData(array("XML Client Error Message " => $parsedData['Error']));
                     throw new Saf_Exception_Upstream('Server returned error with no message', 0);
                 }
             }
             return $parsedData ? $finalPattern == self::API_PARSE_PATTERN_NONE ? $parsedData : current($parsedData) : NULL;
         } else {
             $head = str_replace("\r\n", "\\r\\n<br/>", $rawResponseArray['receivedHeaders']);
             $body = str_replace("\r\n", "\\r\\n<br/>", $rawResponseArray['raw']);
             $libXmlErrors = libxml_get_errors();
             $xmlErrors = array();
             $errorMap = array(LIBXML_ERR_WARNING => 'LIBXML_ERR_WARNING', LIBXML_ERR_ERROR => 'LIBXML_ERR_ERROR', LIBXML_ERR_FATAL => 'LIBXML_ERR_FATAL');
             foreach ($libXmlErrors as $error) {
                 $xmlErrors[] = "{$error->level} {$error->code}" . ($error->file ? " in {$error->file}" : "") . " on line {$error->line},{$error->column}" . ($error->message ? ": {$error->message}" : '');
             }
             $libXmlErrors = 'LIB_XML_ERRORS: <br/>' . implode('<br/>', $xmlErrors) . '<br/>BAD_XML: ' . htmlentities($rawResponseArray['raw']) . '<br/>SERVER_HEADERS: ' . htmlentities($head) . '<br/>SERVER_BODY: ' . htmlentities($body);
             throw new Exception('Unable to parse response XML', 0, Saf_Debug::isEnabled() ? new Exception($libXmlErrors) : NULL);
         }
     } else {
         ob_start();
         print_r($rawResponseArray['failedConnectionInfo']);
         $rawFail = ob_get_contents();
         ob_end_clean();
         if ($rawResponseArray['status'] == 0) {
             if ($rawResponseArray['failedConnectionInfo']['connect_time'] > $this->_client->getConnectionTimeout()) {
                 throw new Saf_Exception_GatewayTimeout('Connection to the remote system timed out.');
             } else {
                 if ($rawResponseArray['failedConnectionInfo']['total_time'] > $this->_client->getTimeout()) {
                     throw new Saf_Exception_GatewayTimeout('Response from the remote system timed out.');
                 }
             }
             $prev = new Exception(htmlentities($rawFail));
             throw new Saf_Exception_BadGateway('Unable to contact the remote system.', $rawResponseArray['status'], $prev);
         }
         $rawRequest = array_key_exists('request', $rawResponseArray) ? 'RAW_REQUEST ' . (array_key_exists('request', $rawResponseArray) ? htmlentities($rawResponseArray['request']) : '') : '';
         $prev = Saf_Debug::isEnabled() ? new Exception('RAW_FAIL ' . htmlentities($rawFail) . '<br/>' . ($rawRequest ? htmlentities($rawRequest) . '<br/>' : '') . ('RAW_RESPONSE ' . htmlentities(htmlentities($rawResponseArray['raw'])))) : NULL;
         throw new Saf_Exception_BadGateway('Communication with the remote system failed.', $rawResponseArray['status'], $prev);
     }
 }
예제 #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);
         }
     }
 }