Exemple #1
0
 public static function getHttpClient()
 {
     static $_instance = null;
     if (is_null($_instance)) {
         // get an http client
         $_instance = new Zendshl_Http_Client();
         // set params
         $_instance->setConfig(array('maxredirects' => 5, 'timeout' => 10));
     }
     return $_instance;
 }
Exemple #2
0
 public static function _doRemoteConfig()
 {
     // if not set to auto check and not forced to do so
     // when user click on "check updates" button
     // we don't actually try to get updates info
     $sefConfig =& Sh404sefFactory::getConfig();
     // prepare a default response object
     $response = new stdClass();
     $response->status = true;
     $response->config = array();
     // check if allowed to read central configuration file
     if (!$sefConfig->canReadRemoteConfig) {
         return $response;
     }
     // get an http client
     $hClient = new Zendshl_Http_Client();
     // request file content
     $adapters = array('Zendshl_Http_Client_Adapter_Curl', 'Zendshl_Http_Client_Adapter_Socket');
     $rawResponse = null;
     foreach ($adapters as $adapter) {
         try {
             // set params
             //$hClient->setUri( self::$_endPoint . '/' . self::$_devConfig);
             $hClient->setUri(self::$_endPoint . '/' . self::$_config);
             $hClient->setConfig(array('maxredirects' => 0, 'timeout' => 10));
             $hClient->setAdapter($adapter);
             $rawResponse = $hClient->request();
             break;
         } catch (Exception $e) {
             // we failed, let's try another method
         }
     }
     // return if error
     if (empty($rawResponse)) {
         $response->status = false;
         return $response;
     }
     if (!is_object($rawResponse) || $rawResponse->isError()) {
         $response->status = false;
         return $response;
     }
     // check the file
     $type = $rawResponse->getHeader('Content-type');
     if (strtolower($type) != 'text/xml' && strtolower($type) != 'application/xml') {
         $response->status = false;
         return $response;
     }
     // should be OK then
     $response->status = true;
     // get an xml object and parse the response
     $rawConfig = simplexml_load_string($rawResponse->getBody());
     // into our response object
     $response->config = array();
     if (!empty($rawConfig)) {
         foreach ($rawConfig->config as $configName => $configElement) {
             foreach ($configElement as $configKey => $values) {
                 if (is_string($values)) {
                     $response->config[$configKey] = $values;
                 } else {
                     $counter = 0;
                     foreach ($values as $arrayName => $arrayValues) {
                         $children = $arrayValues->children();
                         $attr = (string) $arrayValues->attributes();
                         $id = empty($attr) ? $counter : $attr;
                         $count = count($children);
                         if ($count > 0) {
                             foreach ($arrayValues as $key => $value) {
                                 $response->config[$configKey][$id][$key] = (string) $value;
                             }
                         } else {
                             $response->config[$configKey][] = (string) $arrayValues;
                         }
                         $counter++;
                     }
                 }
             }
         }
     }
     // check if this is a valid information file
     return $response;
 }