Ejemplo n.º 1
0
 public function __construct(App_Google_Client $client)
 {
     if (!extension_loaded('curl')) {
         $error = 'The cURL IO handler requires the cURL extension to be enabled';
         $client->getLogger()->critical($error);
         throw new App_Google_IO_Exception($error);
     }
     parent::__construct($client);
 }
Ejemplo n.º 2
0
 public function __construct(App_Google_Client $client)
 {
     if (!ini_get('allow_url_fopen')) {
         $error = 'The stream IO handler requires the allow_url_fopen runtime ' . 'configuration to be enabled';
         $client->getLogger()->critical($error);
         throw new App_Google_IO_Exception($error);
     }
     parent::__construct($client);
 }
Ejemplo n.º 3
0
 public function __construct(App_Google_Client $client)
 {
     if (!function_exists('apc_add')) {
         $error = "Apc functions not available";
         $client->getLogger()->error($error);
         throw new App_Google_Cache_Exception($error);
     }
     $this->client = $client;
 }
Ejemplo n.º 4
0
 public function __construct(App_Google_Client $client)
 {
     if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
         $error = "Memcache functions not available";
         $client->getLogger()->error($error);
         throw new App_Google_Cache_Exception($error);
     }
     $this->client = $client;
     if ($client->isAppEngine()) {
         // No credentials needed for GAE.
         $this->mc = new Memcached();
         $this->connection = true;
     } else {
         $this->host = $client->getClassConfig($this, 'host');
         $this->port = $client->getClassConfig($this, 'port');
         if (empty($this->host) || empty($this->port) && (string) $this->port != "0") {
             $error = "You need to supply a valid memcache host and port";
             $client->getLogger()->error($error);
             throw new App_Google_Cache_Exception($error);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Decode an HTTP Response.
  * @static
  * @throws Google_Service_Exception
  * @param Google_Http_Request $response The http response to be decoded.
  * @param Google_Client $client
  * @return mixed|null
  */
 public static function decodeHttpResponse($response, App_Google_Client $client = null)
 {
     $code = $response->getResponseHttpCode();
     $body = $response->getResponseBody();
     $decoded = null;
     if (intVal($code) >= 300) {
         $decoded = json_decode($body, true);
         $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
         if (isset($decoded['error']) && isset($decoded['error']['message']) && isset($decoded['error']['code'])) {
             // if we're getting a json encoded error definition, use that instead of the raw response
             // body for improved readability
             $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
         } else {
             $err .= ": ({$code}) {$body}";
         }
         $errors = null;
         // Specific check for APIs which don't return error details, such as Blogger.
         if (isset($decoded['error']) && isset($decoded['error']['errors'])) {
             $errors = $decoded['error']['errors'];
         }
         $map = null;
         if ($client) {
             $client->getLogger()->error($err, array('code' => $code, 'errors' => $errors));
             $map = $client->getClassConfig('Google_Service_Exception', 'retry_map');
         }
         throw new App_Google_Service_Exception($err, $code, null, $errors, $map);
     }
     // Only attempt to decode the response, if the response code wasn't (204) 'no content'
     if ($code != '204') {
         if ($response->getExpectedRaw()) {
             return $body;
         }
         $decoded = json_decode($body, true);
         if ($decoded === null || $decoded === "") {
             $error = "Invalid json in service response: {$body}";
             if ($client) {
                 $client->getLogger()->error($error);
             }
             throw new App_Google_Service_Exception($error);
         }
         if ($response->getExpectedClass()) {
             $class = $response->getExpectedClass();
             $decoded = new $class($decoded);
         }
     }
     return $decoded;
 }