⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.14
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Server Software:
Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.25
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
taxi.dev-unit.com
/
app
/
Base
/
SMSTemplate
/
View File Name :
SMSTemplate.php
<?php namespace App\Base\SMSTemplate; use Exception; class SMSTemplate { /** Default SMS template language file name, also used as key prefix */ const DEFAULT_TEMPLATE_FILE = 'sms'; /** @var \Illuminate\Translation\Translator */ protected $translator; /** @var string */ protected $template; /** @var string */ protected $message = ''; /** * SMSTemplate constructor. * * @param string $name * @param array $replace * @param string|null $locale */ public function __construct($name, array $replace = [], $locale = null) { $this->initializeTranslator(); $this->validateTemplate($name, $locale); $this->generateTemplateMessage($replace, $locale); } /** * Get the message generated using the SMS template. * * @return string */ public function getMessage() { return $this->message; } /** * Initialize the translator. * * @throws Exception */ protected function initializeTranslator() { $this->translator = app('translator'); if (!$this->translator->hasForLocale(self::DEFAULT_TEMPLATE_FILE)) { throw new Exception('Missing SMS template language file.'); } } /** * Validate the SMS template key and set the full key name. * * @param string $name * @param string|null $locale * @throws Exception */ protected function validateTemplate($name, $locale = null) { if (!is_string($name)) { throw new Exception('Invalid SMS template name provided.'); } $this->template = self::DEFAULT_TEMPLATE_FILE . '.' . $name; if (!$this->translator->has($this->template, $locale)) { throw new Exception('Provided SMS template does not exist.'); } } /** * Generate and set the message using the SMS template and replacer provided. * * @param array $replace * @param string|null $locale */ protected function generateTemplateMessage(array $replace = [], $locale = null) { $this->message = $this->translator->get($this->template, $replace, $locale); } /** * Get the message when casting to string. * * @return string */ public function __toString() { return $this->getMessage(); } }