芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/www/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php
bus = $bus; $this->events = $events; $this->locale = $locale; $this->manager = $manager; } /** * Send the given notification to the given notifiable entities. * * @param \Illuminate\Support\Collection|array|mixed $notifiables * @param mixed $notification * @return void */ public function send($notifiables, $notification) { $notifiables = $this->formatNotifiables($notifiables); if ($notification instanceof ShouldQueue) { return $this->queueNotification($notifiables, $notification); } return $this->sendNow($notifiables, $notification); } /** * Send the given notification immediately. * * @param \Illuminate\Support\Collection|array|mixed $notifiables * @param mixed $notification * @param array|null $channels * @return void */ public function sendNow($notifiables, $notification, array $channels = null) { $notifiables = $this->formatNotifiables($notifiables); $original = clone $notification; foreach ($notifiables as $notifiable) { if (empty($viaChannels = $channels ?: $notification->via($notifiable))) { continue; } $this->withLocale($this->preferredLocale($notifiable, $notification), function () use ($viaChannels, $notifiable, $original) { $notificationId = Str::uuid()->toString(); foreach ((array) $viaChannels as $channel) { if (! ($notifiable instanceof AnonymousNotifiable && $channel === 'database')) { $this->sendToNotifiable($notifiable, $notificationId, clone $original, $channel); } } }); } } /** * Get the notifiable's preferred locale for the notification. * * @param mixed $notifiable * @param mixed $notification * @return string|null */ protected function preferredLocale($notifiable, $notification) { return $notification->locale ?? $this->locale ?? value(function () use ($notifiable) { if ($notifiable instanceof HasLocalePreference) { return $notifiable->preferredLocale(); } }); } /** * Send the given notification to the given notifiable via a channel. * * @param mixed $notifiable * @param string $id * @param mixed $notification * @param string $channel * @return void */ protected function sendToNotifiable($notifiable, $id, $notification, $channel) { if (! $notification->id) { $notification->id = $id; } if (! $this->shouldSendNotification($notifiable, $notification, $channel)) { return; } $response = $this->manager->driver($channel)->send($notifiable, $notification); $this->events->dispatch( new NotificationSent($notifiable, $notification, $channel, $response) ); } /** * Determines if the notification can be sent. * * @param mixed $notifiable * @param mixed $notification * @param string $channel * @return bool */ protected function shouldSendNotification($notifiable, $notification, $channel) { return $this->events->until( new NotificationSending($notifiable, $notification, $channel) ) !== false; } /** * Queue the given notification instances. * * @param mixed $notifiables * @param \Illuminate\Notifications\Notification $notification * @return void */ protected function queueNotification($notifiables, $notification) { $notifiables = $this->formatNotifiables($notifiables); $original = clone $notification; foreach ($notifiables as $notifiable) { $notificationId = Str::uuid()->toString(); foreach ((array) $original->via($notifiable) as $channel) { $notification = clone $original; $notification->id = $notificationId; if (! is_null($this->locale)) { $notification->locale = $this->locale; } $queue = $notification->queue; if (method_exists($notification, 'viaQueues')) { $queue = $notification->viaQueues()[$channel] ?? null; } $this->bus->dispatch( (new SendQueuedNotifications($notifiable, $notification, [$channel])) ->onConnection($notification->connection) ->onQueue($queue) ->delay(is_array($notification->delay) ? ($notification->delay[$channel] ?? null) : $notification->delay ) ->through( array_merge( method_exists($notification, 'middleware') ? $notification->middleware() : [], $notification->middleware ?? [] ) ) ); } } } /** * Format the notifiables into a Collection / array if necessary. * * @param mixed $notifiables * @return \Illuminate\Database\Eloquent\Collection|array */ protected function formatNotifiables($notifiables) { if (! $notifiables instanceof Collection && ! is_array($notifiables)) { return $notifiables instanceof Model ? new ModelCollection([$notifiables]) : [$notifiables]; } return $notifiables; } }