first commit

This commit is contained in:
XEON\x79
2026-01-08 10:44:51 +07:00
parent 7e9395f9de
commit 2f694b5c1c
7555 changed files with 983730 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace Illuminate\Notifications\Messages;
use Illuminate\Bus\Queueable;
class BroadcastMessage
{
use Queueable;
/**
* The data for the notification.
*
* @var array
*/
public $data;
/**
* Create a new message instance.
*
* @param array $data
* @return void
*/
public function __construct(array $data)
{
$this->data = $data;
}
/**
* Set the message data.
*
* @param array $data
* @return $this
*/
public function data($data)
{
$this->data = $data;
return $this;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Illuminate\Notifications\Messages;
class DatabaseMessage
{
/**
* The data that should be stored with the notification.
*
* @var array
*/
public $data = [];
/**
* Create a new database message.
*
* @param array $data
* @return void
*/
public function __construct(array $data = [])
{
$this->data = $data;
}
}

View File

@@ -0,0 +1,387 @@
<?php
namespace Illuminate\Notifications\Messages;
use Illuminate\Container\Container;
use Illuminate\Contracts\Mail\Attachable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Markdown;
use Illuminate\Support\Traits\Conditionable;
class MailMessage extends SimpleMessage implements Renderable
{
use Conditionable;
/**
* The view to be rendered.
*
* @var array|string
*/
public $view;
/**
* The view data for the message.
*
* @var array
*/
public $viewData = [];
/**
* The Markdown template to render (if applicable).
*
* @var string|null
*/
public $markdown = 'notifications::email';
/**
* The current theme being used when generating emails.
*
* @var string|null
*/
public $theme;
/**
* The "from" information for the message.
*
* @var array
*/
public $from = [];
/**
* The "reply to" information for the message.
*
* @var array
*/
public $replyTo = [];
/**
* The "cc" information for the message.
*
* @var array
*/
public $cc = [];
/**
* The "bcc" information for the message.
*
* @var array
*/
public $bcc = [];
/**
* The attachments for the message.
*
* @var array
*/
public $attachments = [];
/**
* The raw attachments for the message.
*
* @var array
*/
public $rawAttachments = [];
/**
* The tags for the message.
*
* @var array
*/
public $tags = [];
/**
* The metadata for the message.
*
* @var array
*/
public $metadata = [];
/**
* Priority level of the message.
*
* @var int
*/
public $priority;
/**
* The callbacks for the message.
*
* @var array
*/
public $callbacks = [];
/**
* Set the view for the mail message.
*
* @param array|string $view
* @param array $data
* @return $this
*/
public function view($view, array $data = [])
{
$this->view = $view;
$this->viewData = $data;
$this->markdown = null;
return $this;
}
/**
* Set the Markdown template for the notification.
*
* @param string $view
* @param array $data
* @return $this
*/
public function markdown($view, array $data = [])
{
$this->markdown = $view;
$this->viewData = $data;
$this->view = null;
return $this;
}
/**
* Set the default markdown template.
*
* @param string $template
* @return $this
*/
public function template($template)
{
$this->markdown = $template;
return $this;
}
/**
* Set the theme to use with the Markdown template.
*
* @param string $theme
* @return $this
*/
public function theme($theme)
{
$this->theme = $theme;
return $this;
}
/**
* Set the from address for the mail message.
*
* @param string $address
* @param string|null $name
* @return $this
*/
public function from($address, $name = null)
{
$this->from = [$address, $name];
return $this;
}
/**
* Set the "reply to" address of the message.
*
* @param array|string $address
* @param string|null $name
* @return $this
*/
public function replyTo($address, $name = null)
{
if ($this->arrayOfAddresses($address)) {
$this->replyTo += $this->parseAddresses($address);
} else {
$this->replyTo[] = [$address, $name];
}
return $this;
}
/**
* Set the cc address for the mail message.
*
* @param array|string $address
* @param string|null $name
* @return $this
*/
public function cc($address, $name = null)
{
if ($this->arrayOfAddresses($address)) {
$this->cc += $this->parseAddresses($address);
} else {
$this->cc[] = [$address, $name];
}
return $this;
}
/**
* Set the bcc address for the mail message.
*
* @param array|string $address
* @param string|null $name
* @return $this
*/
public function bcc($address, $name = null)
{
if ($this->arrayOfAddresses($address)) {
$this->bcc += $this->parseAddresses($address);
} else {
$this->bcc[] = [$address, $name];
}
return $this;
}
/**
* Attach a file to the message.
*
* @param string|\Illuminate\Contracts\Mail\Attachable|\Illuminate\Mail\Attachment $file
* @param array $options
* @return $this
*/
public function attach($file, array $options = [])
{
if ($file instanceof Attachable) {
$file = $file->toMailAttachment();
}
if ($file instanceof Attachment) {
return $file->attachTo($this);
}
$this->attachments[] = compact('file', 'options');
return $this;
}
/**
* Attach in-memory data as an attachment.
*
* @param string $data
* @param string $name
* @param array $options
* @return $this
*/
public function attachData($data, $name, array $options = [])
{
$this->rawAttachments[] = compact('data', 'name', 'options');
return $this;
}
/**
* Add a tag header to the message when supported by the underlying transport.
*
* @param string $value
* @return $this
*/
public function tag($value)
{
array_push($this->tags, $value);
return $this;
}
/**
* Add a metadata header to the message when supported by the underlying transport.
*
* @param string $key
* @param string $value
* @return $this
*/
public function metadata($key, $value)
{
$this->metadata[$key] = $value;
return $this;
}
/**
* Set the priority of this message.
*
* The value is an integer where 1 is the highest priority and 5 is the lowest.
*
* @param int $level
* @return $this
*/
public function priority($level)
{
$this->priority = $level;
return $this;
}
/**
* Get the data array for the mail message.
*
* @return array
*/
public function data()
{
return array_merge($this->toArray(), $this->viewData);
}
/**
* Parse the multi-address array into the necessary format.
*
* @param array $value
* @return array
*/
protected function parseAddresses($value)
{
return collect($value)->map(function ($address, $name) {
return [$address, is_numeric($name) ? null : $name];
})->values()->all();
}
/**
* Determine if the given "address" is actually an array of addresses.
*
* @param mixed $address
* @return bool
*/
protected function arrayOfAddresses($address)
{
return is_iterable($address) || $address instanceof Arrayable;
}
/**
* Render the mail notification message into an HTML string.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if (isset($this->view)) {
return Container::getInstance()->make('mailer')->render(
$this->view, $this->data()
);
}
$markdown = Container::getInstance()->make(Markdown::class);
return $markdown->theme($this->theme ?: $markdown->getTheme())
->render($this->markdown, $this->data());
}
/**
* Register a callback to be called with the Symfony message instance.
*
* @param callable $callback
* @return $this
*/
public function withSymfonyMessage($callback)
{
$this->callbacks[] = $callback;
return $this;
}
}

View File

@@ -0,0 +1,292 @@
<?php
namespace Illuminate\Notifications\Messages;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Notifications\Action;
class SimpleMessage
{
/**
* The "level" of the notification (info, success, error).
*
* @var string
*/
public $level = 'info';
/**
* The subject of the notification.
*
* @var string
*/
public $subject;
/**
* The notification's greeting.
*
* @var string
*/
public $greeting;
/**
* The notification's salutation.
*
* @var string
*/
public $salutation;
/**
* The "intro" lines of the notification.
*
* @var array
*/
public $introLines = [];
/**
* The "outro" lines of the notification.
*
* @var array
*/
public $outroLines = [];
/**
* The text / label for the action.
*
* @var string
*/
public $actionText;
/**
* The action URL.
*
* @var string
*/
public $actionUrl;
/**
* The name of the mailer that should send the notification.
*
* @var string
*/
public $mailer;
/**
* Indicate that the notification gives information about a successful operation.
*
* @return $this
*/
public function success()
{
$this->level = 'success';
return $this;
}
/**
* Indicate that the notification gives information about an error.
*
* @return $this
*/
public function error()
{
$this->level = 'error';
return $this;
}
/**
* Set the "level" of the notification (success, error, etc.).
*
* @param string $level
* @return $this
*/
public function level($level)
{
$this->level = $level;
return $this;
}
/**
* Set the subject of the notification.
*
* @param string $subject
* @return $this
*/
public function subject($subject)
{
$this->subject = $subject;
return $this;
}
/**
* Set the greeting of the notification.
*
* @param string $greeting
* @return $this
*/
public function greeting($greeting)
{
$this->greeting = $greeting;
return $this;
}
/**
* Set the salutation of the notification.
*
* @param string $salutation
* @return $this
*/
public function salutation($salutation)
{
$this->salutation = $salutation;
return $this;
}
/**
* Add a line of text to the notification.
*
* @param mixed $line
* @return $this
*/
public function line($line)
{
return $this->with($line);
}
/**
* Add a line of text to the notification if the given condition is true.
*
* @param bool $boolean
* @param mixed $line
* @return $this
*/
public function lineIf($boolean, $line)
{
if ($boolean) {
return $this->line($line);
}
return $this;
}
/**
* 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 lines of text to the notification if the given condition is true.
*
* @param bool $boolean
* @param iterable $lines
* @return $this
*/
public function linesIf($boolean, $lines)
{
if ($boolean) {
return $this->lines($lines);
}
return $this;
}
/**
* Add a line of text to the notification.
*
* @param mixed $line
* @return $this
*/
public function with($line)
{
if ($line instanceof Action) {
$this->action($line->text, $line->url);
} elseif (! $this->actionText) {
$this->introLines[] = $this->formatLine($line);
} else {
$this->outroLines[] = $this->formatLine($line);
}
return $this;
}
/**
* Format the given line of text.
*
* @param \Illuminate\Contracts\Support\Htmlable|string|array $line
* @return \Illuminate\Contracts\Support\Htmlable|string
*/
protected function formatLine($line)
{
if ($line instanceof Htmlable) {
return $line;
}
if (is_array($line)) {
return implode(' ', array_map('trim', $line));
}
return trim(implode(' ', array_map('trim', preg_split('/\\r\\n|\\r|\\n/', $line ?? ''))));
}
/**
* Configure the "call to action" button.
*
* @param string $text
* @param string $url
* @return $this
*/
public function action($text, $url)
{
$this->actionText = $text;
$this->actionUrl = $url;
return $this;
}
/**
* Set the name of the mailer that should send the notification.
*
* @param string $mailer
* @return $this
*/
public function mailer($mailer)
{
$this->mailer = $mailer;
return $this;
}
/**
* Get an array representation of the message.
*
* @return array
*/
public function toArray()
{
return [
'level' => $this->level,
'subject' => $this->subject,
'greeting' => $this->greeting,
'salutation' => $this->salutation,
'introLines' => $this->introLines,
'outroLines' => $this->outroLines,
'actionText' => $this->actionText,
'actionUrl' => $this->actionUrl,
'displayableActionUrl' => str_replace(['mailto:', 'tel:'], '', $this->actionUrl ?? ''),
];
}
}