This commit is contained in:
Paolo A
2024-08-13 13:44:16 +00:00
parent 1bbb23088d
commit e796d76612
4001 changed files with 30101 additions and 40075 deletions

View File

@@ -20,6 +20,8 @@ class AnonymousNotifiable
* @param string $channel
* @param mixed $route
* @return $this
*
* @throws \InvalidArgumentException
*/
public function route($channel, $route)
{

View File

@@ -34,7 +34,7 @@ class ChannelManager extends Manager implements DispatcherContract, FactoryContr
*/
public function send($notifiables, $notification)
{
return (new NotificationSender(
(new NotificationSender(
$this, $this->container->make(Bus::class), $this->container->make(Dispatcher::class), $this->locale)
)->send($notifiables, $notification);
}
@@ -49,7 +49,7 @@ class ChannelManager extends Manager implements DispatcherContract, FactoryContr
*/
public function sendNow($notifiables, $notification, array $channels = null)
{
return (new NotificationSender(
(new NotificationSender(
$this, $this->container->make(Bus::class), $this->container->make(Dispatcher::class), $this->locale)
)->sendNow($notifiables, $notification, $channels);
}

View File

@@ -18,7 +18,7 @@ class BroadcastChannel
protected $events;
/**
* Create a new database channel.
* Create a new broadcast channel.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void

View File

@@ -21,6 +21,25 @@ class DatabaseChannel
);
}
/**
* Build an array payload for the DatabaseNotification Model.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return array
*/
protected function buildPayload($notifiable, Notification $notification)
{
return [
'id' => $notification->id,
'type' => method_exists($notification, 'databaseType')
? $notification->databaseType($notifiable)
: get_class($notification),
'data' => $this->getData($notifiable, $notification),
'read_at' => null,
];
}
/**
* Get the data for the notification.
*
@@ -43,21 +62,4 @@ class DatabaseChannel
throw new RuntimeException('Notification is missing toDatabase / toArray method.');
}
/**
* Build an array payload for the DatabaseNotification Model.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return array
*/
protected function buildPayload($notifiable, Notification $notification)
{
return [
'id' => $notification->id,
'type' => get_class($notification),
'data' => $this->getData($notifiable, $notification),
'read_at' => null,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Notifications;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class DatabaseNotification extends Model
@@ -98,6 +99,28 @@ class DatabaseNotification extends Model
return $this->read_at === null;
}
/**
* Scope a query to only include read notifications.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRead(Builder $query)
{
return $query->whereNotNull('read_at');
}
/**
* Scope a query to only include unread notifications.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUnread(Builder $query)
{
return $query->whereNull('read_at');
}
/**
* Create a new database notification collection instance.
*

View File

@@ -92,6 +92,10 @@ class BroadcastNotificationCreated implements ShouldBroadcast
*/
public function broadcastWith()
{
if (method_exists($this->notification, 'broadcastWith')) {
return $this->notification->broadcastWith();
}
return array_merge($this->data, [
'id' => $this->notification->id,
'type' => $this->broadcastType(),

View File

@@ -21,7 +21,7 @@ trait HasDatabaseNotifications
*/
public function readNotifications()
{
return $this->notifications()->whereNotNull('read_at');
return $this->notifications()->read();
}
/**
@@ -31,6 +31,6 @@ trait HasDatabaseNotifications
*/
public function unreadNotifications()
{
return $this->notifications()->whereNull('read_at');
return $this->notifications()->unread();
}
}

View File

@@ -6,10 +6,12 @@ use Illuminate\Container\Container;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Mail\Markdown;
use Traversable;
use Illuminate\Support\Traits\Conditionable;
class MailMessage extends SimpleMessage implements Renderable
{
use Conditionable;
/**
* The view to be rendered.
*
@@ -297,9 +299,7 @@ class MailMessage extends SimpleMessage implements Renderable
*/
protected function arrayOfAddresses($address)
{
return is_array($address) ||
$address instanceof Arrayable ||
$address instanceof Traversable;
return is_iterable($address) || $address instanceof Arrayable;
}
/**
@@ -315,9 +315,10 @@ class MailMessage extends SimpleMessage implements Renderable
);
}
return Container::getInstance()
->make(Markdown::class)
->render($this->markdown, $this->data());
$markdown = Container::getInstance()->make(Markdown::class);
return $markdown->theme($this->theme ?: $markdown->getTheme())
->render($this->markdown, $this->data());
}
/**

View File

@@ -157,6 +157,21 @@ class SimpleMessage
return $this->with($line);
}
/**
* Add lines of text to the notification.
*
* @param iterable $lines
* @return $this
*/
public function lines($lines)
{
foreach ($lines as $line) {
$this->line($line);
}
return $this;
}
/**
* Add a line of text to the notification.
*
@@ -192,7 +207,7 @@ class SimpleMessage
return implode(' ', array_map('trim', $line));
}
return trim(implode(' ', array_map('trim', preg_split('/\\r\\n|\\r|\\n/', $line))));
return trim(implode(' ', array_map('trim', preg_split('/\\r\\n|\\r|\\n/', $line ?? ''))));
}
/**
@@ -239,7 +254,7 @@ class SimpleMessage
'outroLines' => $this->outroLines,
'actionText' => $this->actionText,
'actionUrl' => $this->actionUrl,
'displayableActionUrl' => str_replace(['mailto:', 'tel:'], '', $this->actionUrl),
'displayableActionUrl' => str_replace(['mailto:', 'tel:'], '', $this->actionUrl ?? ''),
];
}
}

View File

@@ -76,7 +76,7 @@ class NotificationSender
return $this->queueNotification($notifiables, $notification);
}
return $this->sendNow($notifiables, $notification);
$this->sendNow($notifiables, $notification);
}
/**
@@ -162,6 +162,11 @@ class NotificationSender
*/
protected function shouldSendNotification($notifiable, $notification, $channel)
{
if (method_exists($notification, 'shouldSend') &&
$notification->shouldSend($notifiable, $channel) === false) {
return false;
}
return $this->events->until(
new NotificationSending($notifiable, $notification, $channel)
) !== false;
@@ -202,7 +207,10 @@ class NotificationSender
(new SendQueuedNotifications($notifiable, $notification, [$channel]))
->onConnection($notification->connection)
->onQueue($queue)
->delay($notification->delay)
->delay(is_array($notification->delay) ?
($notification->delay[$channel] ?? null)
: $notification->delay
)
->through(
array_merge(
method_exists($notification, 'middleware') ? $notification->middleware() : [],

View File

@@ -3,6 +3,7 @@
namespace Illuminate\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Model;
@@ -49,6 +50,13 @@ class SendQueuedNotifications implements ShouldQueue
*/
public $timeout;
/**
* Indicates if the job should be encrypted.
*
* @var bool
*/
public $shouldBeEncrypted = false;
/**
* Create a new job instance.
*
@@ -64,6 +72,8 @@ class SendQueuedNotifications implements ShouldQueue
$this->notifiables = $this->wrapNotifiables($notifiables);
$this->tries = property_exists($notification, 'tries') ? $notification->tries : null;
$this->timeout = property_exists($notification, 'timeout') ? $notification->timeout : null;
$this->afterCommit = property_exists($notification, 'afterCommit') ? $notification->afterCommit : null;
$this->shouldBeEncrypted = $notification instanceof ShouldBeEncrypted;
}
/**
@@ -118,17 +128,17 @@ class SendQueuedNotifications implements ShouldQueue
}
/**
* Get the retry delay for the notification.
* Get the number of seconds before a released notification will be available.
*
* @return mixed
*/
public function retryAfter()
public function backoff()
{
if (! method_exists($this->notification, 'retryAfter') && ! isset($this->notification->retryAfter)) {
if (! method_exists($this->notification, 'backoff') && ! isset($this->notification->backoff)) {
return;
}
return $this->notification->retryAfter ?? $this->notification->retryAfter();
return $this->notification->backoff ?? $this->notification->backoff();
}
/**
@@ -138,11 +148,11 @@ class SendQueuedNotifications implements ShouldQueue
*/
public function retryUntil()
{
if (! method_exists($this->notification, 'retryUntil') && ! isset($this->notification->timeoutAt)) {
if (! method_exists($this->notification, 'retryUntil') && ! isset($this->notification->retryUntil)) {
return;
}
return $this->notification->timeoutAt ?? $this->notification->retryUntil();
return $this->notification->retryUntil ?? $this->notification->retryUntil();
}
/**

View File

@@ -14,15 +14,16 @@
}
],
"require": {
"php": "^7.2.5|^8.0",
"illuminate/broadcasting": "^7.0",
"illuminate/bus": "^7.0",
"illuminate/container": "^7.0",
"illuminate/contracts": "^7.0",
"illuminate/filesystem": "^7.0",
"illuminate/mail": "^7.0",
"illuminate/queue": "^7.0",
"illuminate/support": "^7.0"
"php": "^7.3|^8.0",
"illuminate/broadcasting": "^8.0",
"illuminate/bus": "^8.0",
"illuminate/collections": "^8.0",
"illuminate/container": "^8.0",
"illuminate/contracts": "^8.0",
"illuminate/filesystem": "^8.0",
"illuminate/mail": "^8.0",
"illuminate/queue": "^8.0",
"illuminate/support": "^8.0"
},
"autoload": {
"psr-4": {
@@ -31,11 +32,11 @@
},
"extra": {
"branch-alias": {
"dev-master": "7.x-dev"
"dev-master": "8.x-dev"
}
},
"suggest": {
"illuminate/database": "Required to use the database transport (^7.0)."
"illuminate/database": "Required to use the database transport (^8.0)."
},
"config": {
"sort-packages": true

View File

@@ -51,7 +51,7 @@
@isset($actionText)
@slot('subcopy')
@lang(
"If youre having trouble clicking the \":actionText\" button, copy and paste the URL below\n".
"If you're having trouble clicking the \":actionText\" button, copy and paste the URL below\n".
'into your web browser:',
[
'actionText' => $actionText,