Exceptions.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Illuminate\Support\Facades;
  3. use Illuminate\Contracts\Debug\ExceptionHandler;
  4. use Illuminate\Support\Arr;
  5. use Illuminate\Support\Testing\Fakes\ExceptionHandlerFake;
  6. /**
  7. * @method static void register()
  8. * @method static \Illuminate\Foundation\Exceptions\ReportableHandler reportable(callable $reportUsing)
  9. * @method static \Illuminate\Foundation\Exceptions\Handler renderable(callable $renderUsing)
  10. * @method static \Illuminate\Foundation\Exceptions\Handler map(\Closure|string $from, \Closure|string|null $to = null)
  11. * @method static \Illuminate\Foundation\Exceptions\Handler dontReport(array|string $exceptions)
  12. * @method static \Illuminate\Foundation\Exceptions\Handler dontReportWhen(callable $dontReportWhen)
  13. * @method static \Illuminate\Foundation\Exceptions\Handler ignore(array|string $exceptions)
  14. * @method static \Illuminate\Foundation\Exceptions\Handler dontFlash(array|string $attributes)
  15. * @method static \Illuminate\Foundation\Exceptions\Handler level(string $type, string $level)
  16. * @method static void report(\Throwable $e)
  17. * @method static bool shouldReport(\Throwable $e)
  18. * @method static \Illuminate\Foundation\Exceptions\Handler throttleUsing(callable $throttleUsing)
  19. * @method static \Illuminate\Foundation\Exceptions\Handler stopIgnoring(array|string $exceptions)
  20. * @method static \Illuminate\Foundation\Exceptions\Handler buildContextUsing(\Closure $contextCallback)
  21. * @method static \Symfony\Component\HttpFoundation\Response render(\Illuminate\Http\Request $request, \Throwable $e)
  22. * @method static \Illuminate\Foundation\Exceptions\Handler respondUsing(callable $callback)
  23. * @method static \Illuminate\Foundation\Exceptions\Handler shouldRenderJsonWhen(callable $callback)
  24. * @method static \Illuminate\Foundation\Exceptions\Handler dontReportDuplicates()
  25. * @method static \Illuminate\Contracts\Debug\ExceptionHandler handler()
  26. * @method static void assertReported(\Closure|string $exception)
  27. * @method static void assertReportedCount(int $count)
  28. * @method static void assertNotReported(\Closure|string $exception)
  29. * @method static void assertNothingReported()
  30. * @method static void renderForConsole(\Symfony\Component\Console\Output\OutputInterface $output, \Throwable $e)
  31. * @method static \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake throwOnReport()
  32. * @method static \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake throwFirstReported()
  33. * @method static array reported()
  34. * @method static \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake setHandler(\Illuminate\Contracts\Debug\ExceptionHandler $handler)
  35. *
  36. * @see \Illuminate\Foundation\Exceptions\Handler
  37. * @see \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake
  38. */
  39. class Exceptions extends Facade
  40. {
  41. /**
  42. * Replace the bound instance with a fake.
  43. *
  44. * @param array<int, class-string<\Throwable>>|class-string<\Throwable> $exceptions
  45. * @return \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake
  46. */
  47. public static function fake(array|string $exceptions = [])
  48. {
  49. $exceptionHandler = static::isFake()
  50. ? static::getFacadeRoot()->handler()
  51. : static::getFacadeRoot();
  52. return tap(new ExceptionHandlerFake($exceptionHandler, Arr::wrap($exceptions)), function ($fake) {
  53. static::swap($fake);
  54. });
  55. }
  56. /**
  57. * Get the registered name of the component.
  58. *
  59. * @return string
  60. */
  61. protected static function getFacadeAccessor()
  62. {
  63. return ExceptionHandler::class;
  64. }
  65. }