本文整理汇总了PHP中Response::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getStatusCode方法的具体用法?PHP Response::getStatusCode怎么用?PHP Response::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetStatusCodeReturnsTheStatusCode
public function testGetStatusCodeReturnsTheStatusCode()
{
$response = new Response();
$this->assertEquals($response->getStatusCode(), null);
$response->addHeader('1.0 200 OK');
$this->assertEquals($response->getStatusCode(), 200);
}
示例2: handleError
/**
* @throws HttpException
*/
protected function handleError()
{
$body = (string) $this->response->getBody();
$code = (int) $this->response->getStatusCode();
$content = json_decode($body);
throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
}
示例3: testSetError
/** @dataProvider provideSetError */
public function testSetError($expected, $statusCode, $error, $error_description = null, $error_uri = null)
{
$response = new Response();
$response->setError($statusCode, $error, $error_description, $error_uri);
$this->assertEquals($expected, $response->getContent());
$this->assertEquals($statusCode, $response->getStatusCode());
}
示例4: testIfRedirectReturnsCorrectHttpCodeAndLocationHeader
/**
* @test
* @param $url
* @param $statusCode
* @dataProvider redirectDataProvider
*/
public function testIfRedirectReturnsCorrectHttpCodeAndLocationHeader($url, $statusCode)
{
$response = new Response();
$response->redirect($url, $statusCode);
$this->assertEquals($url, $response->headers->get('Location'));
$this->assertEquals($statusCode, $response->getStatusCode());
}
示例5: handleError
/**
* @throws HttpException
*/
protected function handleError()
{
$body = (string) $this->response->getBody();
$code = (int) $this->response->getStatusCode();
$content = json_decode($body);
$error = $content->errors[0];
throw new HttpException(isset($error) ? $error->description : 'Request not processed.', $code);
}
示例6: testResponseValues
public function testResponseValues()
{
$resource = $this->prophesize(Resource::CLASS);
$resource->asJson()->willReturn('foobar');
$response = new Response($resource->reveal());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('application/hal+json', $response->getHeaderLine('Content-Type'));
$this->assertSame('foobar', (string) $response->getBody());
}
示例7: render
/**
* {@inheritdoc}
*/
public function render(Request $request, Response $response)
{
if (!$this->environment->isSilent()) {
header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage());
foreach ($response->getHeaders() as $name => $value) {
header($name . ': ' . $value);
}
}
echo $this->createTemplate($response);
}
示例8: terminate
/**
* Terminates application.
*
* Renders content or excute redirecting
*
* @param Response $response
*/
public function terminate(Response $response)
{
if ($response->getRedirectUrl() === null) {
header("Content-Type: {$response->getContentType()}; charset=utf-8");
http_response_code($response->getStatusCode());
$response->display();
} else {
header("Location: {$response->getRedirectUrl()}");
}
exit;
}
示例9: validateResponse
/**
* {@inheritdoc}
*/
public function validateResponse(Request $request, Response $response) : bool
{
if (Response::SWITCHING_PROTOCOLS !== $response->getStatusCode()) {
return false;
}
if ('upgrade' !== strtolower($response->getHeader('Connection'))) {
return false;
}
if ('websocket' !== strtolower($response->getHeader('Upgrade'))) {
return false;
}
$key = $request->getHeader('Sec-WebSocket-Key');
if (!$response->hasHeader('Sec-WebSocket-Accept')) {
return false;
}
return $this->responseKey($key) === $response->getHeader('Sec-WebSocket-Accept');
}
示例10: format
/**
* Formats the specified response.
* @param Response $response the response to be formatted.
*/
public function format($response)
{
$charset = $this->encoding === null ? $response->charset : $this->encoding;
if (stripos($this->contentType, 'charset') === false) {
$this->contentType .= '; charset=' . $charset;
}
$response->getHeaders()->set('Content-Type', $this->contentType);
if ($response->data !== null) {
$dom = new DOMDocument($this->version, $charset);
$root = new DOMElement($this->rootTag);
$result = new DOMElement($this->itemTag);
$code = new DOMElement($this->itemTag);
$status = new DOMElement($this->itemTag);
$dom->appendChild($root);
$code->appendChild($response->getStatusCode());
$status->appendChild($response->getIsSuccessful() ? 'success' : 'error');
$messageText = '';
if (!$response->getIsOk()) {
$messageText = $response->statusText;
}
if (is_string($response->data)) {
//For string result we send it like 'message'
$messageText = $response->data;
} elseif ($response->getIsClientError() && isset($response->data['message'])) {
//For HttpExceptions we save message field only to 'message'
$messageText = $response->data['message'];
unset($response->data['message']);
$result->appendChild($response->data);
} else {
//Otherwise send all as result
$result->appendChild($response->data);
}
if ($messageText !== '') {
$message = new DOMElement($this->itemTag);
$message->appendChild($messageText);
$root->appendChild($message);
}
$root->appendChild($result);
$root->appendChild($code);
$root->appendChild($status);
$this->buildXml($root, $response->data);
$response->content = $dom->saveXML();
}
}
示例11: send
protected function send($method, $path, $options)
{
list($url, $headers, $body) = $this->buildRequest($path, $options);
$curl = $this->getCurlHandle();
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, !!$this->debug);
if ($this->debug) {
curl_setopt($curl, CURLOPT_STDERR, is_string($this->debug) ? fopen($this->debug, "a+") : STDOUT);
}
curl_setopt($curl, CURLOPT_HEADER, true);
switch ($method) {
case 'PUT':
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
break;
case 'DELETE':
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
case 'POST':
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
break;
case 'GET':
curl_setopt($curl, CURLOPT_HTTPGET, true);
break;
}
$raw_request_headers = [];
foreach ($headers as $key => $value) {
$raw_request_headers[] = "{$key}: {$value}";
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $raw_request_headers);
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);
$curl_info = curl_getinfo($curl);
list($header, $body) = explode("\r\n\r\n", $result, 2);
if ($body && $this->debug) {
if (is_string($this->debug)) {
error_log("{$body}\n", 3, $this->debug);
} else {
fwrite(is_resource($this->debug) ? $this->debug : STDOUT, "{$body}\n");
}
}
$response = new Response($header, $body, $curl_info);
if ($this->http_errors && $response->getStatusCode() >= 400) {
$exception = new BadResponseException();
$exception->setResponse($response);
throw $exception;
}
return $response;
}
示例12: filterResponse
/**
* Converts the HttpKernel response to a BrowserKit response.
*
* @param Response $response A Response instance
*
* @return Response A Response instance
*/
protected function filterResponse($response)
{
$headers = $response->headers->all();
if ($response->headers->getCookies()) {
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
$headers['Set-Cookie'] = $cookies;
}
// this is needed to support StreamedResponse
ob_start();
$response->sendContent();
$content = ob_get_clean();
return new DomResponse($content, $response->getStatusCode(), $headers);
}
示例13: replaceSubmission
/**
*
* @param TiiSubmission $submission
*/
public function replaceSubmission($submission)
{
$params_merge = $this->getResubmissionFormHash($submission);
if (is_null($submission->getSubmissionDataPath()) && is_null($submission->getSubmissionDataUrl())) {
$params_merge['custom_submission_data'] = $submission->getSubmissionDataText();
} else {
if (is_null($submission->getSubmissionDataUrl())) {
// CURL uploading with @ has been deprecated in PHP 5.5
if (class_exists('CURLFile')) {
$finfo = new finfo(FILEINFO_MIME);
$mimetype = $finfo->file($submission->getSubmissionDataPath());
$params_merge['custom_submission_data'] = new CurlFile($submission->getSubmissionDataPath(), $mimetype);
} else {
$params_merge['custom_submission_data'] = '@' . $submission->getSubmissionDataPath();
}
}
}
$transport = $this->transportData($params_merge);
$response = new Response($this);
if ($response->getStatusCode() == 'failure') {
throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
} else {
$dom = $response->getDomObject();
$tiiSubmission = new TiiSubmission();
$tiiSubmission->setSubmissionId($dom->getElementsByTagName('lis_result_sourcedid')->item(0)->nodeValue);
$tiiSubmission->setTextExtract(@$dom->getElementsByTagName('submission_data_extract')->item(0)->nodeValue);
$response->setSubmission($tiiSubmission);
}
return $response;
}
示例14: encodeResponse
/**
* {@inheritdoc}
*/
public function encodeResponse(Response $response) : string
{
return sprintf("HTTP/%s %d %s\r\n%s\r\n", $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase(), $this->encodeHeaders($response->getHeaders()));
}
示例15: testReturnsStatusCode
public function testReturnsStatusCode()
{
$response = new Response('', 201);
$this->assertSame(201, $response->getStatusCode());
}