⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
erp.dev-unit.com
/
vendor
/
tzsk
/
sms
/
src
/
View File Name :
Sms.php
<?php namespace Tzsk\Sms; use Exception; use ReflectionClass; use Tzsk\Sms\Contracts\Driver; class Sms { protected array $config; protected array $settings; protected string $driver; protected Builder $builder; public function __construct(array $config) { $this->config = $config; $this->setBuilder(new Builder()); $this->via($this->config['default']); } public function to($recipients): self { $this->builder->to($recipients); return $this; } public function via($driver): self { $this->driver = $driver; $this->validateDriver(); $this->builder->via($driver); $this->settings = $this->config['drivers'][$driver]; return $this; } public function send($message, $callback = null) { if ($message instanceof Builder) { return $this->setBuilder($message)->dispatch(); } $this->builder->send($message); if (! $callback) { return $this; } $driver = $this->getDriverInstance(); $driver->message($message); call_user_func($callback, $driver); return $driver->send(); // return $this->setBuilder($this->builder->send($message))->dispatch(); } public function dispatch() { $this->driver = $this->builder->getDriver() ?: $this->driver; if (empty($this->driver)) { $this->via($this->config['default']); } $driver = $this->getDriverInstance(); $driver->message($this->builder->getBody()); $driver->to($this->builder->getRecipients()); return $driver->send(); } protected function setBuilder(Builder $builder): self { $this->builder = $builder; return $this; } protected function getDriverInstance(): Driver { $this->validateDriver(); $class = $this->config['map'][$this->driver]; return new $class($this->settings); } protected function validateDriver() { $conditions = [ 'Driver not selected or default driver does not exist.' => empty($this->driver), 'Driver not found in config file. Try updating the package.' => empty($this->config['drivers'][$this->driver]) || empty($this->config['map'][$this->driver]), 'Driver source not found. Please update the package.' => ! class_exists($this->config['map'][$this->driver]), 'Driver must be an instance of Contracts\Driver.' => ! (new ReflectionClass($this->config['map'][$this->driver]))->isSubclassOf(Driver::class), ]; foreach ($conditions as $ex => $condition) { throw_if($condition, new Exception($ex)); } } }