Initial Spark Install

This commit is contained in:
Deon George
2017-11-03 16:26:07 +11:00
commit b1a5807eb3
766 changed files with 128896 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
namespace Laravel\Spark\Notifications;
use RuntimeException;
use Laravel\Spark\Team;
use Illuminate\Notifications\Notification;
use Laravel\Spark\Contracts\Repositories\NotificationRepository;
class SparkChannel
{
/**
* The notifications repository implementation.
*
* @var NotificationRepository
*/
private $notifications;
/**
* Create a new spark channel instance.
*
* @param NotificationRepository $notifications
* @return void
*/
public function __construct(NotificationRepository $notifications)
{
$this->notifications = $notifications;
}
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification)
{
if (method_exists($notifiable, 'routeNotificationForSpark')) {
$notifiable = $notifiable->routeNotificationForSpark() ? $notifiable->routeNotificationForSpark() : $notifiable;
}
$users = $notifiable instanceof Team ? $notifiable->users : [$notifiable];
$data = $this->getData($notifiable, $notification);
foreach ($users as $user) {
$this->notifications->create($user, $data);
}
}
/**
* Get the data for the notification.
*
* @param mixed $notifiable
* @param Notification $notification
* @return array
*
* @throws RuntimeException
*/
protected function getData($notifiable, Notification $notification)
{
$message = $notification->toSpark($notifiable);
return [
'icon' => $message->icon,
'body' => $message->body,
'from' => $message->from,
'action_text' => $message->actionText,
'action_url' => $message->actionUrl,
];
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Laravel\Spark\Notifications;
use Laravel\Spark\User as SparkUser;
class SparkNotification
{
/**
* The message icon.
*
* @var string
*/
public $icon = 'fa-bell';
/**
* The message body.
*
* @var string
*/
public $body;
/**
* The user that created the message.
*
* @var string
*/
public $from;
/**
* The text for the action button.
*
* @var string
*/
public $actionText;
/**
* The URL for the action button.
*
* @var string
*/
public $actionUrl;
/**
* Create a new message instance.
*
* @param string $body
* @return void
*/
public function __construct($body = '')
{
$this->body = $body;
}
/**
* Set the message icon.
*
* @param string $icon
* @return $this
*/
public function icon($icon)
{
$this->icon = $icon;
return $this;
}
/**
* Set the message body.
*
* @param string $body
* @return $this
*/
public function body($body)
{
$this->body = $body;
return $this;
}
/**
* Set the message author.
*
* @param SparkUser $from
* @return $this
*/
public function from(SparkUser $from)
{
$this->from = $from;
return $this;
}
/**
* Set the button text.
*
* @param string $text
* @param string $url
* @return $this
*/
public function action($text, $url)
{
$this->actionText = $text;
$this->actionUrl = $url;
return $this;
}
}