本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\NotFoundHttpException::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP NotFoundHttpException::getStatusCode方法的具体用法?PHP NotFoundHttpException::getStatusCode怎么用?PHP NotFoundHttpException::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\NotFoundHttpException
的用法示例。
在下文中一共展示了NotFoundHttpException::getStatusCode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} else {
if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) {
return response()->json(['errors' => ['The access token is expired.']], $e->getStatusCode());
} else {
if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) {
return response()->json(['errors' => ['The access token is invalid.']], $e->getStatusCode());
} else {
if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) {
return response()->json(['errors' => ['The internal server error is occured.']], $e->getStatusCode());
} else {
if ($e instanceof NotFoundHttpException) {
return response()->json(['errors' => ['The resource hasn\'t found.']], $e->getStatusCode());
} else {
if ($e instanceof MethodNotAllowedHttpException) {
return response()->json(['errors' => ['The method doesn\'t allowed for this resource.']], $e->getStatusCode());
}
}
}
}
}
}
return parent::render($request, $e);
}
示例2: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($e instanceof TokenExpiredException) {
return response()->json(['token_expired'], $e->getStatusCode());
}
if ($e instanceof TokenInvalidException) {
return response()->json(['token_invalid'], $e->getStatusCode());
}
return parent::render($request, $e);
}
示例3: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($request->acceptsJson() && $request->ajax()) {
// Provide JSON response
$response = ['success' => false, 'error' => ''];
// Set response HTTP code and headers
if ($e instanceof HttpExceptionInterface) {
$code = $e->getStatusCode();
$headers = $e->getHeaders();
} else {
$code = 500;
$headers = [];
}
if ($e instanceof MaxUploadSizeException) {
$response['error'] = 'File too big.';
} elseif ($e instanceof DisallowedFileTypeException) {
$response['error'] = 'Disallowed file type.';
} else {
$response['error'] = 'Server error.';
}
// Add exception to response if debug mode is turned on
if (config('app.debug') === true) {
$response['exception'] = ['exception' => get_class($e), 'code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTrace(), 'file' => $e->getFile(), 'file_line' => $e->getLine()];
}
return response()->json($response, $code, $headers);
} else {
// Normal HTML error page
return parent::render($request, $e);
}
}
示例4: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
/**
* Response Exception as Json
*
*/
if ($request->wantsJson()) {
$error = new \stdclass();
$error->error = true;
if ($e instanceof NotFoundHttpException) {
$error->code = $e->getStatusCode();
} else {
$error->code = $e->getCode();
}
if ($error->code == 0) {
$error->code = 400;
}
if ($e instanceof ValidatorException) {
$error->message = $e->getMessageBag();
} else {
$error->message = $e->getMessage();
if (\App::environment('local')) {
$error->file = $e->getFile();
$error->line = $e->getLine();
}
}
return response()->json($error, $error->code);
}
return parent::render($request, $e);
}
示例5: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($e->getStatusCode() == '404') {
return redirect('/');
}
return parent::render($request, $e);
}
示例6: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} else {
if ($e instanceof TokenExpiredException) {
return response()->json(['token_expired'], $e->getStatusCode());
} else {
if ($e instanceof TokenInvalidException) {
return response()->json(['token_invalid'], $e->getStatusCode());
} else {
if ($e->getMessage() === 'The token could not be parsed from the request') {
return response()->json(['token_invalid'], 400);
}
}
}
}
return parent::render($request, $e);
}
示例7: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} elseif ($e instanceof HttpException && \App::isLocal() === false) {
Response::json(['result' => false, 'message' => $e->getMessage()])->setStatusCode($e->getStatusCode())->send();
exit;
}
return parent::render($request, $e);
}
示例8: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($request->isMethod('get')) {
if ($e->getStatusCode() == 404) {
return response()->view('index');
}
}
return parent::render($request, $e);
}
示例9: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
$space = $this->getViewSpace($request);
$status = $e->getStatusCode();
if (view()->exists($space . '.errors.' . $status)) {
return response()->view($space . '.errors.' . $status, compact('e'), $status);
}
return parent::render($request, $e);
}
示例10: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} else {
if ($e instanceof InvalidCredentialsException || $e instanceof NoAuthenticationException) {
return $e->render();
} else {
if ($e instanceof TokenExpiredException) {
return response()->json(['error' => 'token_expired', 'error_description' => 'Your token has expired.'], $e->getStatusCode());
} else {
if ($e instanceof TokenInvalidException) {
return response()->json(['error' => 'token_invalid', 'error_description' => 'The provided token was invalid.'], $e->getStatusCode());
} else {
if ($e instanceof JWTException) {
return response()->json(['error' => 'token_error', 'error_description' => 'There was an error generating or reading the access token. Please try again.'], $e->getStatusCode());
}
}
}
}
}
return parent::render($request, $e);
}
示例11: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($e instanceof HttpException) {
// HTTP Exception detected, render custom error view
$statuscode = $e->getStatusCode();
$viewpath = "clearboard.pages.errors.{$statuscode}";
if (view()->exists($viewpath)) {
return response()->view($viewpath);
}
}
return parent::render($request, $e);
}
示例12: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($e instanceof HttpException) {
$errorData = ["message" => $e->getMessage(), "httpCode" => $e->getStatusCode(), "code" => $e->getCode()];
if ($request->ajax()) {
return response()->json($errorData, $errorData['httpCode']);
} else {
return response()->view('errors.phylab', $errorData, $errorData['httpCode']);
}
}
return parent::render($request, $e);
}
示例13: onKernelRequest
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$route = $request->attributes->get('_route');
if (empty($route)) {
$route = $request->attributes->get('_master_request_route');
}
if (!$this->provider->isItemWhitelisted($route)) {
$notFoundException = new NotFoundHttpException('Sorry, the page that you requested was not found.');
$statusCode = $notFoundException->getStatusCode();
$parameters = ['status_code' => $statusCode, 'status_text' => Response::$statusTexts[$statusCode], 'currentContent' => '', 'exception' => FlattenException::create($notFoundException), 'logger' => $this->logger];
$view = View::create($parameters);
$view->setFormat(self::VIEW_FORMAT);
$view->setTemplate($this->findTemplate($request, $statusCode, $this->kernel->isDebug()));
$response = $this->viewHandler->handle($view);
$event->setResponse($response);
}
}
示例14: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($request->segment(1) == 'api' || $request->ajax()) {
if ($this->isHttpException($e)) {
$message = 'Http exception occurred';
switch ($e->getStatusCode()) {
case 404:
$message = 'Method not found';
break;
case 405:
$message = 'Method not allowed';
break;
case 401:
$message = 'Unauthorized';
break;
case 501:
$message = 'Maintenance';
break;
}
return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => $message, 'timestamp' => Carbon::now()], $e->getStatusCode());
} else {
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
return response()->json(['request_id' => uniqid(), 'status' => 'not found', 'message' => $e->getMessage(), 'timestamp' => Carbon::now()], $e->getStatusCode());
}
}
}
if (!config('app.debug', false) && !$this->isHttpException($e)) {
switch ($e->getStatusCode()) {
case 500:
if ($request->segment(1) == 'api' || $request->ajax()) {
return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => 'Internal server error', 'timestamp' => Carbon::now()], 500);
}
return response()->view('errors.500', ['exception' => $e], 500);
break;
case 405:
return response()->view('errors.500', ['exception' => $e], 405);
break;
}
}
return parent::render($request, $e);
}