本文整理匯總了PHP中Symfony\Component\HttpFoundation\JsonResponse::getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP JsonResponse::getStatusCode方法的具體用法?PHP JsonResponse::getStatusCode怎麽用?PHP JsonResponse::getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\JsonResponse
的用法示例。
在下文中一共展示了JsonResponse::getStatusCode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testUnauthorizedPostUserRegistrationAction
public function testUnauthorizedPostUserRegistrationAction()
{
$this->configHandler->shouldReceive('getParameter')->with('allow_self_registration')->once()->andReturn(false);
$response = new JsonResponse(array(), 403);
$this->assertEquals($response->getStatusCode(), $this->controller->postUserRegistrationAction('json')->getStatusCode());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $this->controller->postUserRegistrationAction('json'));
}
示例2: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$response = new JsonResponse();
if ($exception instanceof HttpExceptionInterface) {
$response->setStatusCode($exception->getStatusCode());
} elseif ($exception instanceof AuthenticationException) {
$response->setStatusCode(403);
} else {
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
}
$response->setData(array('message' => $exception->getMessage(), 'status_code' => $response->getStatusCode(), 'trace' => $exception->getTrace(), 'code' => $exception->getCode()));
$event->setResponse($response);
}
示例3: refreshAction
/**
* refresh a given access credentials
* @param $request
* @return string|Response
*/
public function refreshAction(Request $request)
{
try {
$refreshCode = $this->getRefreshCode($request);
$clientSecret = $this->getClientSecret($request);
$credentials = $this->accessProvider->refresh($request, $refreshCode, $clientSecret);
$response = new JsonResponse(['access_code' => $credentials->getAccessCode(), 'refresh_code' => $credentials->getRefreshCode(), 'lifetime' => $credentials->getLifetime()]);
} catch (SoauthException $e) {
$data = [];
if ($e instanceof BadDataException) {
$data['errors'] = $e->getErrors();
}
$response = new JsonResponse($data, Response::HTTP_BAD_REQUEST);
}
$this->info('< Response', ['status_code' => $response->getStatusCode()]);
return $response;
}
示例4: testConstructorWithCustomStatus
public function testConstructorWithCustomStatus()
{
$response = new JsonResponse(array(), 202);
$this->assertSame(202, $response->getStatusCode());
}
示例5: getDebugTraceResponse
/**
* Return response with debug trace.
*
* @param \Exception $exception
* @param int $statusCode
*
* @return Response
*/
private function getDebugTraceResponse(\Exception $exception, $statusCode)
{
$request = $this->application->getRequest();
$response = (new \Symfony\Component\Debug\ExceptionHandler())->createResponse($exception);
$response->setStatusCode($statusCode);
if (in_array('application/json', $request->getAcceptableContentTypes())) {
$response = new JsonResponse($response->getContent(), $response->getStatusCode(), $response->headers->all());
}
return $response;
}
示例6: array
$rendered = $app['twig']->render('api.json', array('data' => $data));
$rendered = preg_replace('/[\\t]+/', '', preg_replace('/[\\r\\n]+/', '', $rendered));
$rendered = json_decode($rendered);
$response = new JsonResponse($rendered, 429);
$response->headers->set('Retry-After', ceil($seconds));
return $response;
}
}, Silex\Application::EARLY_EVENT);
$app->after(function (Request $request, Response $response, Silex\Application $app) {
// apply the current reponse code and status to the return envelope
$message = $response->getContent();
$message = preg_replace('/[\\t]+/', '', preg_replace('/[\\r\\n]+/', '', $message));
$message = json_decode($message);
// make sure the response is a standard envelope
if (is_object($message) and property_exists($message, 'meta')) {
$code = $response->getStatusCode();
$message->meta->code = $code;
if (substr($code, 0, 1) === '2') {
$message->meta->success = true;
}
$response->setContent(json_encode($message));
}
});
$app->error(function (\Exception $e, $code) use($app) {
if ($app['debug']) {
return;
}
// 404.html, or 40x.html, or 4xx.html, or error.html
$templates = array('errors/' . $code . '.html', 'errors/' . substr($code, 0, 2) . 'x.html', 'errors/' . substr($code, 0, 1) . 'xx.html', 'errors/default.html');
return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
});
示例7: assert403
private function assert403(JsonResponse $jsonResponse)
{
$this->assertEquals(403, $jsonResponse->getStatusCode());
}