本文整理匯總了PHP中Google_Http_Request::getExpectedClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP Google_Http_Request::getExpectedClass方法的具體用法?PHP Google_Http_Request::getExpectedClass怎麽用?PHP Google_Http_Request::getExpectedClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Google_Http_Request
的用法示例。
在下文中一共展示了Google_Http_Request::getExpectedClass方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: decodeHttpResponse
/**
* Decode an HTTP Response.
* @static
* @throws Google_Service_Exception
* @param Google_Http_Request $response The http response to be decoded.
* @return mixed|null
*/
public static function decodeHttpResponse($response)
{
$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'];
}
throw new Google_Service_Exception($err, $code, null, $errors);
}
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
if ($code != '204') {
$decoded = json_decode($body, true);
if ($decoded === null || $decoded === "") {
throw new Google_Service_Exception("Invalid json in service response: {$body}");
}
if ($response->getExpectedClass()) {
$class = $response->getExpectedClass();
$decoded = new $class($decoded);
}
}
return $decoded;
}
示例2: nextChunk
/**
* 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 Google_Http_Request($this->resumeUri, 'PUT', $headers, $chunk);
if ($this->client->getClassConfig("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 Google_Http_REST::decodeHttpResponse($response);
}
}
示例3: testRequestParameters
public function testRequestParameters()
{
$url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
$url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
$request = new Google_Http_Request($url);
$request->setExpectedClass("Google_Client");
$this->assertEquals(2, count($request->getQueryParams()));
$request->setQueryParam("hi", "there");
$this->assertEquals($url2, $request->getUrl());
$this->assertEquals("Google_Client", $request->getExpectedClass());
$urlPath = "/foo/bar";
$request = new Google_Http_Request($urlPath);
$this->assertEquals($urlPath, $request->getUrl());
$request->setBaseComponent("http://example.com");
$this->assertEquals("http://example.com" . $urlPath, $request->getUrl());
$url3a = 'http://localhost:8080/foo/bar';
$url3b = 'foo=a&foo=b&wowee=oh+my';
$url3c = 'foo=a&foo=b&wowee=oh+my&hi=there';
$request = new Google_Http_Request($url3a . "?" . $url3b, "POST");
$request->setQueryParam("hi", "there");
$request->maybeMoveParametersToBody();
$this->assertEquals($url3a, $request->getUrl());
$this->assertEquals($url3c, $request->getPostBody());
$url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
$request = new Google_Http_Request($url);
$this->assertEquals(2, count($request->getQueryParams()));
$request->setQueryParam("hi", "there");
$base = $request->getBaseComponent();
$request->setBaseComponent($base . '/upload');
$this->assertEquals($url4, $request->getUrl());
}
示例4: makePutRequest
/**
* Sends a PUT-Request to google drive and parses the response,
* setting the appropiate variables from the response()
*
* @param Google_Http_Request $httpRequest the Reuqest which will be send
*
* @return false|mixed false when the upload is unfinished or the decoded http response
*
*/
private function makePutRequest(Google_Http_Request $httpRequest)
{
if ($this->client->getClassConfig("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 Google_Http_REST::decodeHttpResponse($response, $this->client);
}
}
示例5: testRequestParameters
public function testRequestParameters()
{
$url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
$url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
$request = new Google_Http_Request($this->getClient(), $url);
$request->setExpectedClass("Google_Client");
$this->assertEquals(2, count($request->getQueryParams()));
$request->setQueryParam("hi", "there");
$this->assertEquals($url2, $request->getUrl());
$this->assertEquals("Google_Client", $request->getExpectedClass());
$url3a = 'http://localhost:8080/foo/bar';
$url3b = 'foo=a&foo=b&wowee=oh+my';
$url3c = 'foo=a&foo=b&wowee=oh+my&hi=there';
$request = new Google_Http_Request($this->getClient(), $url3a . "?" . $url3b, "POST");
$request->setQueryParam("hi", "there");
$request->maybeMoveParametersToBody();
$this->assertEquals($url3a, $request->getUrl());
$this->assertEquals($url3c, $request->getPostBody());
}
示例6: decodeHttpResponse
/**
* 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, 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 Google_Service_Exception($err, $code, null, $errors, $map);
echo json_encode(array('status' => FALSE, 'response-code' => $code, 'response' => $err, 'message' => $errors, "map" => $map));
die;
}
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
if ($code != '204') {
$decoded = json_decode($body, true);
if ($decoded === null || $decoded === "") {
$error = "Invalid json in service response: {$body}";
if ($client) {
$client->getLogger()->error($error);
}
//throw new Google_Service_Exception($error);
echo json_encode(array('status' => FALSE, 'response-code' => $code, 'response' => $error, 'message' => $body));
die;
}
if ($response->getExpectedClass()) {
$class = $response->getExpectedClass();
$decoded = new $class($decoded);
}
}
return $decoded;
}