本文整理汇总了PHP中HttpResponse::getHttpCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::getHttpCode方法的具体用法?PHP HttpResponse::getHttpCode怎么用?PHP HttpResponse::getHttpCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::getHttpCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes this batch. This sends the captured requests to the server as one batch.
*
* @throws ClientException
* @return bool - true if processing of the batch was or the HttpResponse object in case of a failure. A successful process just means that tha parts were processed. Each part has it's own response though and should be checked on its own.
*/
public function process()
{
$this->stopCapture();
$this->setBatchRequest(true);
$data = '';
$batchParts = $this->getBatchParts();
if (count($batchParts) == 0) {
throw new ClientException('Can\'t process empty batch.');
}
/** @var $partValue BatchPart */
foreach ($batchParts as $partValue) {
$data .= '--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL;
$data .= 'Content-Type: application/x-arango-batchpart' . HttpHelper::EOL;
if (!is_null($partValue->getId())) {
$data .= 'Content-Id: ' . (string) $partValue->getId() . HttpHelper::EOL . HttpHelper::EOL;
} else {
$data .= HttpHelper::EOL;
}
$data .= (string) $partValue->getRequest() . HttpHelper::EOL;
}
$data .= '--' . HttpHelper::MIME_BOUNDARY . '--' . HttpHelper::EOL . HttpHelper::EOL;
$params = array();
$url = UrlHelper::appendParamsUrl(Urls::URL_BATCH, $params);
$this->_batchResponse = $this->_connection->post($url, $data);
if ($this->_batchResponse->getHttpCode() !== 200) {
return $this->_batchResponse;
}
$body = $this->_batchResponse->getBody();
$body = trim($body, '--' . HttpHelper::MIME_BOUNDARY . '--');
$batchParts = $this->splitWithContentIdKey('--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL, $body);
foreach ($batchParts as $partKey => $partValue) {
$response = new HttpResponse($partValue);
$body = $response->getBody();
$response = new HttpResponse($body);
$batchPartResponses[$partKey] = $response;
$this->getPart($partKey)->setResponse($batchPartResponses[$partKey]);
}
return $this;
}
示例2: executeRequest
/**
* Execute an HTTP request and return the results
*
* This function will throw if no connection to the server can be established or if
* there is a problem during data exchange with the server.
*
* will restore it.
*
* @throws Exception
*
* @param string $method - HTTP request method
* @param string $url - HTTP URL
* @param string $data - data to post in body
* @param array $customHeader - any array containing header elements
*
* @return HttpResponse
*/
private function executeRequest($method, $url, $data, $customHeader = array())
{
HttpHelper::validateMethod($method);
$database = $this->getDatabase();
if ($database === '') {
$url = '/_db/' . '_system' . $url;
} else {
$url = '/_db/' . $database . $url;
}
// create request data
if ($this->_batchRequest === false) {
if ($this->_captureBatch === true) {
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, true);
$request = HttpHelper::buildRequest($this->_options, $method, $url, $data, $customHeader);
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, false);
} else {
$request = HttpHelper::buildRequest($this->_options, $method, $url, $data, $customHeader);
}
if ($this->_captureBatch === true) {
$batchPart = $this->doBatch($method, $request);
if (!is_null($batchPart)) {
return $batchPart;
}
}
} else {
$this->_batchRequest = false;
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, true);
$request = HttpHelper::buildRequest($this->_options, $method, $url, $data, $customHeader);
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, false);
}
$traceFunc = $this->_options[ConnectionOptions::OPTION_TRACE];
if ($traceFunc) {
// call tracer func
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
list($header) = HttpHelper::parseHttpMessage($request, $url, $method);
$headers = HttpHelper::parseHeaders($header);
$traceFunc(new TraceRequest($headers[2], $method, $url, $data));
} else {
$traceFunc('send', $request);
}
}
// open the socket. note: this might throw if the connection cannot be established
$handle = $this->getHandle();
if ($handle) {
// send data and get response back
if ($traceFunc) {
// only issue syscall if we need it
$startTime = microtime(true);
}
$result = HttpHelper::transfer($handle, $request);
if ($traceFunc) {
// only issue syscall if we need it
$timeTaken = microtime(true) - $startTime;
}
$status = socket_get_status($handle);
if ($status['timed_out']) {
throw new ClientException('Got a timeout while waiting for the server\'s response', 408);
}
if (!$this->_useKeepAlive) {
// must close the connection
fclose($handle);
}
$response = new HttpResponse($result, $url, $method);
if ($traceFunc) {
// call tracer func
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
$traceFunc(new TraceResponse($response->getHeaders(), $response->getHttpCode(), $response->getBody(), $timeTaken));
} else {
$traceFunc('receive', $result);
}
}
return $response;
}
throw new ClientException('Whoops, this should never happen');
}
示例3: testGetHttpCode
/**
* @dataProvider httpCodeProvider
*
* @param int $code
*/
public function testGetHttpCode($code)
{
$response = new HttpResponse('', $code, '');
$this->assertEquals($code, $response->getHttpCode());
}