Notification.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Illuminate\Support\Facades;
  3. use Illuminate\Notifications\AnonymousNotifiable;
  4. use Illuminate\Notifications\ChannelManager;
  5. use Illuminate\Support\Testing\Fakes\NotificationFake;
  6. /**
  7. * @method static void send(\Illuminate\Support\Collection|mixed $notifiables, mixed $notification)
  8. * @method static void sendNow(\Illuminate\Support\Collection|mixed $notifiables, mixed $notification, array|null $channels = null)
  9. * @method static mixed channel(string|null $name = null)
  10. * @method static string getDefaultDriver()
  11. * @method static string deliversVia()
  12. * @method static void deliverVia(string $channel)
  13. * @method static \Illuminate\Notifications\ChannelManager locale(string $locale)
  14. * @method static mixed driver(string|null $driver = null)
  15. * @method static \Illuminate\Notifications\ChannelManager extend(string $driver, \Closure $callback)
  16. * @method static array getDrivers()
  17. * @method static \Illuminate\Contracts\Container\Container getContainer()
  18. * @method static \Illuminate\Notifications\ChannelManager setContainer(\Illuminate\Contracts\Container\Container $container)
  19. * @method static \Illuminate\Notifications\ChannelManager forgetDrivers()
  20. * @method static void assertSentOnDemand(string|\Closure $notification, callable|null $callback = null)
  21. * @method static void assertSentTo(mixed $notifiable, string|\Closure $notification, callable|null $callback = null)
  22. * @method static void assertSentOnDemandTimes(string $notification, int $times = 1)
  23. * @method static void assertSentToTimes(mixed $notifiable, string $notification, int $times = 1)
  24. * @method static void assertNotSentTo(mixed $notifiable, string|\Closure $notification, callable|null $callback = null)
  25. * @method static void assertNothingSent()
  26. * @method static void assertNothingSentTo(mixed $notifiable)
  27. * @method static void assertSentTimes(string $notification, int $expectedCount)
  28. * @method static void assertCount(int $expectedCount)
  29. * @method static \Illuminate\Support\Collection sent(mixed $notifiable, string $notification, callable|null $callback = null)
  30. * @method static bool hasSent(mixed $notifiable, string $notification)
  31. * @method static \Illuminate\Support\Testing\Fakes\NotificationFake serializeAndRestore(bool $serializeAndRestore = true)
  32. * @method static array sentNotifications()
  33. * @method static void macro(string $name, object|callable $macro)
  34. * @method static void mixin(object $mixin, bool $replace = true)
  35. * @method static bool hasMacro(string $name)
  36. * @method static void flushMacros()
  37. *
  38. * @see \Illuminate\Notifications\ChannelManager
  39. * @see \Illuminate\Support\Testing\Fakes\NotificationFake
  40. */
  41. class Notification extends Facade
  42. {
  43. /**
  44. * Replace the bound instance with a fake.
  45. *
  46. * @return \Illuminate\Support\Testing\Fakes\NotificationFake
  47. */
  48. public static function fake()
  49. {
  50. return tap(new NotificationFake, function ($fake) {
  51. static::swap($fake);
  52. });
  53. }
  54. /**
  55. * Begin sending a notification to an anonymous notifiable on the given channels.
  56. *
  57. * @param array $channels
  58. * @return \Illuminate\Notifications\AnonymousNotifiable
  59. */
  60. public static function routes(array $channels)
  61. {
  62. $notifiable = new AnonymousNotifiable;
  63. foreach ($channels as $channel => $route) {
  64. $notifiable->route($channel, $route);
  65. }
  66. return $notifiable;
  67. }
  68. /**
  69. * Begin sending a notification to an anonymous notifiable.
  70. *
  71. * @param string $channel
  72. * @param mixed $route
  73. * @return \Illuminate\Notifications\AnonymousNotifiable
  74. */
  75. public static function route($channel, $route)
  76. {
  77. return (new AnonymousNotifiable)->route($channel, $route);
  78. }
  79. /**
  80. * Get the registered name of the component.
  81. *
  82. * @return string
  83. */
  84. protected static function getFacadeAccessor()
  85. {
  86. return ChannelManager::class;
  87. }
  88. }