コード例 #1
0
 /**
  * Send the next part of the file to upload.
  * @param [$chunk] the next set of bytes to send. If false will used $data passed
  * at construct time.
  */
 public function nextChunk($chunk = false)
 {
     if (false == $this->resumeUri) {
         $this->resumeUri = $this->getResumeUri();
     }
     if (false == $chunk) {
         $chunk = substr($this->data, $this->progress, $this->chunkSize);
     }
     $lastBytePos = $this->progress + strlen($chunk) - 1;
     $headers = array('content-range' => "bytes {$this->progress}-{$lastBytePos}/{$this->size}", 'content-type' => $this->request->getRequestHeader('content-type'), 'content-length' => $this->chunkSize, 'expect' => '');
     $httpRequest = new Postman_Google_Http_Request($this->resumeUri, 'PUT', $headers, $chunk);
     if ($this->client->getClassConfig("Postman_Google_Http_Request", "enable_gzip_for_uploads")) {
         $httpRequest->enableGzip();
     } else {
         $httpRequest->disableGzip();
     }
     $response = $this->client->getIo()->makeRequest($httpRequest);
     $response->setExpectedClass($this->request->getExpectedClass());
     $code = $response->getResponseHttpCode();
     $this->httpResultCode = $code;
     if (308 == $code) {
         // Track the amount uploaded.
         $range = explode('-', $response->getResponseHeader('range'));
         $this->progress = $range[1] + 1;
         // Allow for changing upload URLs.
         $location = $response->getResponseHeader('location');
         if ($location) {
             $this->resumeUri = $location;
         }
         // No problems, but upload not complete.
         return false;
     } else {
         return Postman_Google_Http_REST::decodeHttpResponse($response, $this->client);
     }
 }
コード例 #2
0
ファイル: Abstract.php プロジェクト: DanMaiman/Awfulkid
 public function __construct(Postman_Google_Client $client)
 {
     $this->client = $client;
     $timeout = $client->getClassConfig('Postman_Google_IO_Abstract', 'request_timeout_seconds');
     if ($timeout > 0) {
         $this->setTimeout($timeout);
     }
 }
コード例 #3
0
ファイル: Memcache.php プロジェクト: DanMaiman/Awfulkid
 public function __construct(Postman_Google_Client $client)
 {
     if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
         $error = "Memcache functions not available";
         $client->getLogger()->error($error);
         throw new Postman_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 Postman_Google_Cache_Exception($error);
         }
     }
 }
コード例 #4
0
ファイル: Abstract.php プロジェクト: DanMaiman/Awfulkid
 /**
  * @param Postman_Google_Client $client  The current Google client
  */
 public function __construct(Postman_Google_Client $client)
 {
     $this->setLevel($client->getClassConfig('Postman_Google_Logger_Abstract', 'level'));
     $format = $client->getClassConfig('Postman_Google_Logger_Abstract', 'log_format');
     $this->logFormat = $format ? $format : self::DEFAULT_LOG_FORMAT;
     $format = $client->getClassConfig('Postman_Google_Logger_Abstract', 'date_format');
     $this->dateFormat = $format ? $format : self::DEFAULT_DATE_FORMAT;
     $this->allowNewLines = (bool) $client->getClassConfig('Postman_Google_Logger_Abstract', 'allow_newlines');
 }