File: //proc/self/cwd/wp-content/plugins/luman-plus/Includes/App/Notification/NotificationService.php
<?php
namespace lumanPlus\App\Notification;
use lumanPlus\App\Notification\Core\NotificationManager;
use lumanPlus\App\Notification\Traits\{HasNotification, HasPattern};
use lumanPlus\Core\Helper;
use lumanPlus\Core\Logger;
class NotificationService {
use HasNotification, HasPattern;
private $driver = null;
private $service = null;
private $to = null;
public function setDriver(string $driver): NotificationService
{
$this->driver = $driver;
return $this;
}
public function setService(string $service): NotificationService
{
$this->service = $service;
return $this;
}
public function setRecipient (string $to): NotificationService
{
$this->to = $to;
return $this;
}
public function sendWithPattern(string $pattern, array $attributes): bool
{
$driver = $this->driver ?? $this->getDefaultDriver();
$service = $this->service ?? $this->getDefaultService();
$patternCode = $this->checkPattern($pattern,$service);
if ( empty($patternCode) ) {
Logger::warning('Pattern not set for service',[
'service' => $service,
'pattern' => $pattern,
'driver' => $driver
]);
return false;
}
$manager = new NotificationManager($driver, $service);
$driverInstance = $manager->getDriver();
return $driverInstance->sendWithPattern($patternCode,$attributes,$this->to);
}
private function getDefaultDriver(): string {
return Helper::getOption('default_driver');
}
private function getDefaultService(): string {
return Helper::getOption('default_service');
}
}