本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getStatusCode方法的具体用法?PHP Response::getStatusCode怎么用?PHP Response::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertSuccess
public function assertSuccess()
{
if ($this->response->getStatusCode() != 200) {
$this->fail($this->response->getContent());
}
return $this;
}
示例2: testUnspecified
public function testUnspecified()
{
$this->mapping->setParameter('missing');
$this->action->execute($this->mapping, null, $this->request, $this->response);
$this->assertNotEmpty($this->response->getContent());
$this->assertEquals(400, $this->response->getStatusCode());
}
示例3: parseNonPhtml
public static function parseNonPhtml(Response $response, $file)
{
if (!file_exists($file = file_exists($file = self::getPath() . $file) ? $file : (file_exists($file . '.html') ? $file . '.html' : (file_exists($file . '.xhtml') ? $file . '.xhtml' : (file_exists($file . '.php') ? $file . '.php' : $file))))) {
if ($response->getStatusCode() == 200) {
$response->setStatusCode(404);
}
$response->setContent($file = (string) new Phtml('/errors/' . $response->getStatusCode(), FALSE, 'default'));
} else {
if (strpos($file = realpath($file), realpath(Skin::getPath())) !== 0) {
throw new \Exception('Unknown skin path: "' . $file . '".');
}
$file = str_replace('sitemap.xml.php', 'sitemap.xml', $file);
$repository = new PhpRepository();
$response->headers->set('Content-Type', $repository->findType(strtolower(substr(strrchr($file, '.'), 1)) ?: $file) ?: 'text/plain');
if (basename($file) == 'sitemap.xml') {
$phtml = new Phtml(NULL);
$file = $phtml->parsePhtml($file . '.php');
} else {
$file = file_get_contents($file);
}
$response->setContent($file);
}
$response->headers->set('Cache-Control', 'max-age=604800');
$response->headers->set('Content-Length', strlen($file));
return $response;
}
示例4: getStatusCode
/**
* @return int
*/
public function getStatusCode()
{
if ($this->response === null) {
return null;
}
return $this->response->getStatusCode();
}
示例5: logResponse
/**
* Logs a response
*
* @param Response $response
*/
protected function logResponse(Response $response)
{
if ($response instanceof RedirectResponse) {
$this->logger->info('< ' . $response->getStatusCode() . ' ' . $response->getTargetUrl());
} else {
$this->logger->info('< ' . $response->getStatusCode());
}
}
示例6: logResponse
/**
* @param \Symfony\Component\HttpFoundation\Response $response
*
* @return void
*/
protected function logResponse(Response $response)
{
if ($response instanceof RedirectResponse) {
$message = sprintf('%s Response %s [%s], target URL %s', $this->getSapi(), APPLICATION, $response->getStatusCode(), $response->getTargetUrl());
} else {
$message = sprintf('%s Response %s [%s]', $this->getSapi(), APPLICATION, $response->getStatusCode());
}
$this->logger->info($message, ['response' => $response]);
}
示例7: adaptResponse
/**
* @param InternalResponse $iResponse
* @return Response
*/
public function adaptResponse(InternalResponse $iResponse)
{
$response = new Response($iResponse->getContent(), $iResponse->getStatusCode(), $iResponse->getHeaders());
if ($this->request) {
$response->prepare($this->request);
}
if ($response->getStatusCode() !== 200) {
$response->setContent(Response::$statusTexts[$response->getStatusCode()]);
return $response;
}
return $response;
}
示例8: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
}
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
$attributes[$key] = is_object($value) ? sprintf('Object(%s)', get_class($value)) : $value;
}
$this->data = array(
'format' => $request->getRequestFormat(),
'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html',
'status_code' => $response->getStatusCode(),
'request_query' => $request->query->all(),
'request_request' => $request->request->all(),
'request_headers' => $request->headers->all(),
'request_server' => $request->server->all(),
'request_cookies' => $request->cookies->all(),
'request_attributes' => $attributes,
'response_headers' => $responseHeaders,
'session_attributes' => $request->hasSession() ? $request->getSession()->getAttributes() : array(),
);
}
示例9: serialize
/**
* Serialize a response.
*
* @param \Symfony\Component\HttpFoundation\Response $response
*
* @return string
*/
public function serialize(Response $response)
{
$content = $response->getContent();
$statusCode = $response->getStatusCode();
$headers = $response->headers;
return serialize(compact('content', 'statusCode', 'headers'));
}
示例10: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
}
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if (is_object($value)) {
$attributes[$key] = sprintf('Object(%s)', get_class($value));
if (is_callable(array($value, '__toString'))) {
$attributes[$key] .= sprintf(' = %s', (string) $value);
}
} else {
$attributes[$key] = $value;
}
}
$content = null;
try {
$content = $request->getContent();
} catch (\LogicException $e) {
// the user already got the request content as a resource
$content = false;
}
$this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_attributes' => $request->hasSession() ? $request->getSession()->all() : array(), 'path_info' => $request->getPathInfo());
}
示例11: getMessage
private function getMessage(Response $response)
{
if (500 >= $response->getStatusCode() && $response->getStatusCode() < 600) {
$crawler = new Crawler();
$crawler->addHtmlContent($response->getContent());
if ($crawler->filter('.text-exception h1')->count() > 0) {
$exceptionMessage = trim($crawler->filter('.text-exception h1')->text());
$trace = '';
if ($crawler->filter('#traces-0 li')->count() > 0) {
list($trace) = explode("\n", trim($crawler->filter('#traces-0 li')->text()));
}
return $message = 'Internal Server Error: ' . $exceptionMessage . ' ' . $trace;
}
}
return $response->getContent();
}
示例12: assertJsonResponse
/**
* Test API response status
*
* @param Response $response
* @param int $statusCode
* @param string $contentType
*/
public static function assertJsonResponse($response, $statusCode = 201, $contentType = 'application/json')
{
\PHPUnit_Framework_TestCase::assertEquals($statusCode, $response->getStatusCode(), $response->getContent());
if ($contentType !== '') {
\PHPUnit_Framework_TestCase::assertTrue($response->headers->contains('Content-Type', $contentType), $response->headers);
}
}
示例13: assertJsonResponse
/**
* @param Response $response
* @param int $statusCode
* @param bool $checkValidJson
* @param string $contentType
* @return array Json decoded
*/
protected function assertJsonResponse(Response $response, $statusCode = 200, $checkValidJson = true, $contentType = 'application/json')
{
$content = null;
$this->assertEquals($statusCode, $response->getStatusCode(), sprintf("Status code is not expected %d, got %d instead\n%s", $statusCode, $response->getStatusCode(), $response->getContent()));
// If content-type is an URL, check for Location header (DELETE)
if (strpos($contentType, '://') === false) {
$this->assertTrue($response->headers->contains('Content-Type', $contentType), sprintf('No "Content-Type" header set to %s', $contentType));
} else {
$this->assertTrue($response->headers->contains('Location', $contentType), sprintf('No "Location" header set to %s', $contentType));
}
if ($checkValidJson) {
$content = json_decode($response->getContent(), true);
$this->assertTrue($content !== null && $content !== false, 'is response valid json: [' . $response->getContent() . ']');
}
return $content;
}
示例14: handle
/**
* @param HTTPApiClient $apiClient
* @param Response $response
* @param ClientRequest $clientRequest
* @return mixed
*/
public function handle(HTTPApiClient $apiClient, Response $response, ClientRequest $clientRequest)
{
if (200 != $response->getStatusCode()) {
$e = new BadResponseException();
$this->throwException($e, $response, $clientRequest);
}
}
示例15: assertForm
/**
* @param Response $response
*/
protected function assertForm(Response $response)
{
$this->assertEquals(200, $response->getStatusCode());
$this->assertRegExp('/form/', $response->getContent());
$this->assertNotRegExp('/<html/', $response->getContent());
$this->assertNotRegExp('/_username/', $response->getContent());
}