Exceptions.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 ignore(array|string $exceptions)
  13. * @method static \Illuminate\Foundation\Exceptions\Handler dontFlash(array|string $attributes)
  14. * @method static \Illuminate\Foundation\Exceptions\Handler level(string $type, void $level)
  15. * @method static void report(\Throwable $e)
  16. * @method static bool shouldReport(\Throwable $e)
  17. * @method static \Illuminate\Foundation\Exceptions\Handler throttleUsing(callable $throttleUsing)
  18. * @method static \Illuminate\Foundation\Exceptions\Handler stopIgnoring(array|string $exceptions)
  19. * @method static \Illuminate\Foundation\Exceptions\Handler buildContextUsing(\Closure $contextCallback)
  20. * @method static \Symfony\Component\HttpFoundation\Response render(\Illuminate\Http\Request $request, \Throwable $e)
  21. * @method static \Illuminate\Foundation\Exceptions\Handler respondUsing(callable $callback)
  22. * @method static \Illuminate\Foundation\Exceptions\Handler shouldRenderJsonWhen(callable $callback)
  23. * @method static \Illuminate\Foundation\Exceptions\Handler dontReportDuplicates()
  24. * @method static \Illuminate\Contracts\Debug\ExceptionHandler handler()
  25. * @method static void assertNothingReported()
  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 renderForConsole(\Symfony\Component\Console\Output\OutputInterface $output, \Throwable $e)
  30. * @method static \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake throwFirstReported()
  31. * @method static \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake setHandler(\Illuminate\Contracts\Debug\ExceptionHandler $handler)
  32. *
  33. * @see \Illuminate\Foundation\Exceptions\Handler
  34. * @see \Illuminate\Contracts\Debug\ExceptionHandler
  35. * @see \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake
  36. */
  37. class Exceptions extends Facade
  38. {
  39. /**
  40. * Replace the bound instance with a fake.
  41. *
  42. * @param array<int, class-string<\Throwable>>|class-string<\Throwable> $exceptions
  43. * @return \Illuminate\Support\Testing\Fakes\ExceptionHandlerFake
  44. */
  45. public static function fake(array|string $exceptions = [])
  46. {
  47. $exceptionHandler = static::isFake()
  48. ? static::getFacadeRoot()->handler()
  49. : static::getFacadeRoot();
  50. return tap(new ExceptionHandlerFake($exceptionHandler, Arr::wrap($exceptions)), function ($fake) {
  51. static::swap($fake);
  52. });
  53. }
  54. /**
  55. * Get the registered name of the component.
  56. *
  57. * @return string
  58. */
  59. protected static function getFacadeAccessor()
  60. {
  61. return ExceptionHandler::class;
  62. }
  63. }