public function __construct(App_Google_Client $client)
 {
     $this->client = $client;
     $timeout = $client->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds');
     if ($timeout > 0) {
         $this->setTimeout($timeout);
     }
 }
 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);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Creates a new task runner with exponential backoff support.
  *
  * @param Google_Client $client The current API client
  * @param string $name The name of the current task (used for logging)
  * @param callable $action The task to run and possibly retry
  * @param array $arguments The task arguments
  * @throws Google_Task_Exception when misconfigured
  */
 public function __construct(App_Google_Client $client, $name, $action, array $arguments = array())
 {
     $config = (array) $client->getClassConfig('Google_Task_Runner');
     if (isset($config['initial_delay'])) {
         if ($config['initial_delay'] < 0) {
             throw new App_Google_Task_Exception('Task configuration `initial_delay` must not be negative.');
         }
         $this->delay = $config['initial_delay'];
     }
     if (isset($config['max_delay'])) {
         if ($config['max_delay'] <= 0) {
             throw new App_Google_Task_Exception('Task configuration `max_delay` must be greater than 0.');
         }
         $this->maxDelay = $config['max_delay'];
     }
     if (isset($config['factor'])) {
         if ($config['factor'] <= 0) {
             throw new App_Google_Task_Exception('Task configuration `factor` must be greater than 0.');
         }
         $this->factor = $config['factor'];
     }
     if (isset($config['jitter'])) {
         if ($config['jitter'] <= 0) {
             throw new App_Google_Task_Exception('Task configuration `jitter` must be greater than 0.');
         }
         $this->jitter = $config['jitter'];
     }
     if (isset($config['retries'])) {
         if ($config['retries'] < 0) {
             throw new App_Google_Task_Exception('Task configuration `retries` must not be negative.');
         }
         $this->maxAttempts += $config['retries'];
     }
     if (!is_callable($action)) {
         throw new App_Google_Task_Exception('Task argument `$action` must be a valid callable.');
     }
     $this->name = $name;
     $this->client = $client;
     $this->action = $action;
     $this->arguments = $arguments;
 }
Exemplo n.º 4
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;
 }
 /**
  * @param Google_Client $client  The current Google client
  */
 public function __construct(App_Google_Client $client)
 {
     $this->setLevel($client->getClassConfig('App_Google_Logger_Abstract', 'level'));
     $format = $client->getClassConfig('App_Google_Logger_Abstract', 'log_format');
     $this->logFormat = $format ? $format : self::DEFAULT_LOG_FORMAT;
     $format = $client->getClassConfig('App_Google_Logger_Abstract', 'date_format');
     $this->dateFormat = $format ? $format : self::DEFAULT_DATE_FORMAT;
     $this->allowNewLines = (bool) $client->getClassConfig('App_Google_Logger_Abstract', 'allow_newlines');
 }