当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception\NotFoundHttpException类代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\NotFoundHttpException的典型用法代码示例。如果您正苦于以下问题:PHP NotFoundHttpException类的具体用法?PHP NotFoundHttpException怎么用?PHP NotFoundHttpException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NotFoundHttpException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * Render an exception into an HTTP response.
  * 该方法响应异常信息到客户端 : 该方法返回的数据必须是一个response对象
  * 异常的处理是在请求结束前处理,因此这里的render 方法直接设定为返回异常信息给响应。
  * @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);
     }
     $msg = $e->getmessage();
     if ($e instanceof InvalidArgumentException) {
         return response()->json(['data' => $msg, 'state' => '901', 'timeStamp' => time()]);
     }
     if ($e instanceof UnexpectedValueException) {
         return response()->json(['data' => $msg, 'state' => '902', 'timeStamp' => time()]);
     }
     if ($e instanceof SignatureInvalidException) {
         return response()->json(['data' => $msg, 'state' => '903', 'timeStamp' => time()]);
         // return response()->view('welcome', [], 503);
         // return  response("ddddd")->header("x-at",'xxx');
     }
     if ($e instanceof BeforeValidException) {
         return response()->json(['data' => $msg, 'state' => '904', 'timeStamp' => time()]);
     }
     if ($e instanceof ExpiredException) {
         return response()->json(['data' => $msg, 'state' => '905', 'timeStamp' => time()]);
     }
     if ($e instanceof CustomException) {
         return response()->json(['data' => $msg, 'state' => '1005', 'timeStamp' => time()]);
     }
     return parent::render($request, $e);
 }
开发者ID:xzungshao,项目名称:lar5-one,代码行数:36,代码来源:Handler.php

示例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)
 {
     \App\Http\Controllers\BaseController::setHeader();
     /**
      * Handle Service Exceptions
      */
     if ($e instanceof \App\Exceptions\ServiceException) {
         $response = array('status' => $e->getCode(), 'message' => $e->getMessage());
         ServiceLog::requestLog($request, $response);
         return \Response::json($response);
     }
     if (!\Config::get('app.debug')) {
         if ($e instanceof ModelNotFoundException) {
             $e = new NotFoundHttpException($e->getMessage(), $e);
         }
         if ($e instanceof \Illuminate\Contracts\Container\BindingResolutionException) {
             $response = array('status' => 604, 'message' => '相应服务没有启动');
         } elseif ($e instanceof \Symfony\Component\Debug\Exception\FatalErrorException) {
             $response = array('status' => 605, 'message' => 'method wrong');
         } else {
             $response = array('status' => $e->getCode() ?: 606, 'message' => $e->getMessage() ?: '请检查请求数据');
         }
         ServiceLog::errorLog($request, $response);
         return \Response::json($response);
     }
     return parent::render($request, $e);
 }
开发者ID:icevisual,项目名称:transfer,代码行数:34,代码来源:Handler.php

示例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);
     }
     return parent::render($request, $e);
 }
开发者ID:birendragurung,项目名称:larapp,代码行数:14,代码来源:Handler.php

示例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)
 {
     /*
      * Notification on TokenMismatchException
      */
     if ($e instanceof TokenMismatchException) {
         Notification::error(trans('global.Security token expired. Please, repeat your request.'));
         return redirect()->back()->withInput();
     }
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     if ($this->isHttpException($e)) {
         return $this->toIlluminateResponse($this->renderHttpException($e), $e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             return response()->view('errors.500', [], 500);
         }
         return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
     }
 }
开发者ID:webfactorybulgaria,项目名称:Base,代码行数:35,代码来源:Handler.php

示例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 HttpException) {
         // call i18n middleware manually since http exceptions won't be sent through it
         (new Internationalization())->handle($request, function () {
         });
     }
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if ($e instanceof MethodNotAllowedHttpException) {
         abort(403, 'Method not allowed.');
     }
     if ($e instanceof PrettyPageException && PHP_SAPI != "cli") {
         return $e->showErrorPage();
     }
     if ($e instanceof ValidationException) {
         // quick fix for returning 422
         // @see https://prinzeugen.net/custom-responses-of-laravel-validations/
         return $e->getResponse()->setStatusCode(200);
     }
     // render exceptions with whoops
     if (config('app.debug')) {
         foreach ($this->dontReport as $type) {
             if ($e instanceof $type) {
                 return parent::render($request, $e);
             }
         }
         return $this->renderExceptionWithWhoops($e);
     }
     return response()->view('errors.brief', ['code' => 0, 'message' => 'cmn']);
 }
开发者ID:printempw,项目名称:blessing-skin-server,代码行数:39,代码来源:Handler.php

示例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 debug is enabled in local environment dump stack trace
     if (config('app.debug') and app()->environment('local')) {
         return class_exists('Whoops\\Run') ? $this->whoops($e) : parent::render($request, $e);
     }
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     // HTTP exceptions are are normally intentionally thrown and its safe to show their message
     if ($this->isHttpException($e)) {
         $code = $e->getStatusCode();
         $message = $e->getMessage();
         if (empty($message)) {
             $message = isset($this->httpCodes[$code]) ? $this->httpCodes[$code] : $this->httpCodes[500];
         }
     } else {
         $code = $e->getCode();
         if (!isset($this->httpCodes[$code])) {
             $code = 500;
         }
         $message = $this->httpCodes[$code];
     }
     // If a custom view exist use it, otherwise use generic error page
     $view = view()->exists("errors/{$code}") ? "errors/{$code}" : 'layouts/error';
     // Data for the view
     $data = ['title' => $message, 'code' => $code];
     return response()->view($view, $data, $code);
 }
开发者ID:LeandrosilvaDG,项目名称:Wiki,代码行数:36,代码来源:Handler.php

示例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);
     }
     if (config('app.debug')) {
         return parent::render($request, $e);
     }
     if ($e instanceof TokenMismatchException) {
         return redirect()->back()->withInput($request->except('_token'))->withErrors('A sua sessão expirou. Tente novamente.');
     }
     if (!$this->isHttpException($e)) {
         $pathInfo = $request->getPathInfo();
         $url = $request->url();
         $method = $request->method();
         $message = $e->getMessage() ?: get_class($e);
         $data = ['pathInfo' => $pathInfo, 'url' => $url, 'method' => $method, 'exception' => $message, 'input' => $request->all()];
         \Mail::send('emails.notify-webmaster', $data, function ($message) use($url) {
             $message->from('no-reply@andremiguelaa.com');
             $message->to('andremiguelaa@gmail.com', 'André Ascensão');
             $message->subject("Exception at {$url}");
         });
     }
     return parent::render($request, $e);
 }
开发者ID:andremiguelaa,项目名称:quiz-cascata,代码行数:32,代码来源:Handler.php

示例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->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);
     }
 }
开发者ID:kimoi,项目名称:madokami.com,代码行数:40,代码来源:Handler.php

示例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 Cartalyst\Sentinel\Checkpoints\NotActivatedException) {
         //            return response()->view('errors.custom', [], 500);
         return redirect('wait')->withErrors($e->getMessage());
     }
     if ($e instanceof Cartalyst\Sentinel\Checkpoints\ThrottlingException) {
         $free = $e->getFree()->format('d M, h:i:s a');
         switch ($e->getType()) {
             case 'global':
                 $message = "Our site appears to be spammed. To give eveything a chance to calm down, please try again after {$free}.";
                 break;
             case 'ip':
                 $message = "Too many unauthorized attemps have been made against your IP address. Please wait until {$free} before trying again.";
                 break;
             case 'user':
                 $message = "Too many unauthorized attemps have been made against your account. For your security, your account is locked until {$free}.";
                 break;
         }
         return redirect('auth/login')->withErrors($message);
     }
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     return parent::render($request, $e);
 }
开发者ID:reysmerwvr,项目名称:jenion,代码行数:34,代码来源:Handler.php

示例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 \UnknownPlayerException) {
         Bugsnag::notifyException($e);
         return response()->view('error', ['error' => $e->getMessage()]);
     }
     if ($e instanceof \DestinyException) {
         Bugsnag::notifyException($e);
         return response()->view('error', ['error' => $e->getMessage(), 'bungie' => true]);
     }
     if ($e instanceof \DestinyLegacyPlatformException) {
         return response()->view('error', ['error' => $e->getMessage(), 'bungie' => true]);
     }
     if (\Config::get('app.debug')) {
         \Session::flash('alert', sprintf("%s (Line %d): %s", $e->getFile(), $e->getLine(), $e->getMessage()));
     } else {
         if (strlen($e->getMessage()) > 1) {
             \Session::flash('alert', $e->getMessage());
         }
     }
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if (config('app.debug') && app()->environment() != 'testing') {
         return $this->renderExceptionWithWhoops($request, $e);
     }
     return parent::render($request, $e);
 }
开发者ID:TrackerNetwork,项目名称:DestinyStatus,代码行数:35,代码来源:Handler.php

示例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);
       }
       return parent::render($request, $e);*/
     $debug = env('APP_DEBUG');
     if ($debug == 0) {
         if ($this->isHttpException($e)) {
             return $this->renderHttpException($e);
         } else {
             if ($e instanceof NotFoundHttpException) {
                 return response()->view('errors.404', [], 400);
             } elseif ($e instanceof FatalErrorException) {
                 return response()->view('errors.500', [], 500);
             } elseif ($e instanceof handleError) {
                 return response()->view('errors.500', [], 500);
             } elseif ($e instanceof ModelNotFoundException) {
                 return response()->view('errors.500', [], 500);
             } else {
                 return response()->view('errors.500', [], 500);
             }
         }
     } else {
         if ($debug == 1) {
             //si es verdadero esta en modo debug y muestra el error
             if ($e instanceof ModelNotFoundException) {
                 $e = new NotFoundHttpException($e->getMessage(), $e);
             }
             return parent::render($request, $e);
         }
     }
 }
开发者ID:jda1586,项目名称:MCS-DHI,代码行数:40,代码来源:Handler.php

示例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 ($request->wantsJson()) {
         // Define the response
         $response = ['error' => 'Sorry, something went wrong: '];
         // If the app is in debug mode
         if (config('app.debug')) {
             // Add the exception class name, message and stack trace to response
             $response['exception'] = get_class($e);
             // Reflection might be better here
             $response['message'] = $e->getMessage();
             $response['trace'] = $e->getTrace();
         }
         // Default response of 400
         $status = 400;
         // If this exception is an instance of HttpException
         if ($this->isHttpException($e)) {
             // Grab the HTTP status code from the Exception
             $status = $e->getStatusCode();
         }
         // Return a JSON response with the response array and status code
         return response()->json($response, $status);
     }
     // Default to the parent class' implementation of handler
     return parent::render($request, $e);
 }
开发者ID:becast,项目名称:GameReviewSite,代码行数:36,代码来源:Handler.php

示例13: 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)
 {
     # Gazzete Errors
     if (Auth::check() && Auth::user()->hasRole(Role::SUBSCRIBER)) {
         if ($e instanceof NotFoundHttpException) {
             return redirect()->route('gazette.errors.404');
         }
         if ($e instanceof TokenMismatchException) {
             return redirect()->route('gazette.errors.unauthorized');
         }
     }
     # Management Errors
     if (Auth::check() && Auth::user()->hasRole(Role::ADMINISTRATOR)) {
         if ($e instanceof NotFoundHttpException) {
             return redirect()->route('management.errors.404');
         }
         if ($e instanceof TokenMismatchException) {
             return redirect()->route('management.errors.unauthorized');
         }
         if ($e instanceof ModelNotFoundException) {
             $e = new NotFoundHttpException($e->getMessage(), $e);
         }
     }
     return parent::render($request, $e);
 }
开发者ID:Hub-IT,项目名称:gazette,代码行数:32,代码来源:Handler.php

示例14: render

 /**
  * HTTPレスポンスに対応する例外をレンダー
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception               $e
  *
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if (config('app.debug')) {
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Hander\PrettyPageHander());
         return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
     }
     // CSRFトークンが存在しない、トークン不一致時に投げられる。
     // TokenMismatchException例外を403で処理。
     // もちろん適切であれば、HTTPステータスは自由に設定できる。
     if ($e instanceof TokenMismatchException) {
         // abortヘルパーによりSymfony\Component\HttpFoundation\Exception\HttpException例外が
         // 投げられ、再度このrenderメソッドで処理される。この例外の
         // ステータスコードに一致するビューがapp/resources/views/errorsに
         // 存在していれば、そのビューが表示される。今回は403.blade.phpファイルが
         // 存在しているため、このファイルの内容がエラーページとして表示される。
         abort(403);
     }
     // このrenderメソッドに最初から含まれている処理。
     // EloquentのfindOrFailソッドなどが投げるModelNotFoundException例外を
     // 404エラーにしている。
     if ($e instanceof ModelNotFoundException) {
         // 404エラー例外はabort(404)を使わず、次のように発生可能。
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     return parent::render($request, $e);
 }
开发者ID:kazumaf0913,项目名称:test,代码行数:35,代码来源:Handler.php

示例15: 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);
     }
     return parent::render($request, $e);
     /* COMMENT ABOVE AND UNCOMMENT BELOW TO REDIRECT FOR CUSTOM ERROR HANDLING */
     /* if ($this->isHttpException($e)) {
                 switch ($e->getStatusCode()) {
                     // not found
                     case 404:
                         die("404 Redirect to Page not found here in app/Exceptions/Handler.php");
                         return redirect()->guest('home');
                         break;
     
                     // internal error
                     case '500':
                         die("500 Redirect to internal error page here in app/Exceptions/Handler.php");
                         return redirect()->guest('home');
                         break;
     
                     default:
                         return $this->renderHttpException($e);
                         break;
                 }
             } else {
                 return parent::render($request, $e);
             } */
 }
开发者ID:DinanathThakur,项目名称:Flash-Sale-Ecommerce-Portal-PHP,代码行数:36,代码来源:Handler.php


注:本文中的Symfony\Component\HttpKernel\Exception\NotFoundHttpException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。