The Sender class uses a Singleton pattern
masterThe Sender class is implemented as a Singleton to ensure efficient resource management and consistent state throughout a single request lifecycle. This allows for easy provider switching and centralized configuration management.
Key methods in the Sender singleton:
getInstance(): Retrieves the singleton instance.setProvider($class): Sets the active provider.setConfig($config): Sets the provider configuration.setMobile($mobile): Sets the recipient number.setMessage($message): Sets the message content.setQueue($bool): Toggles queue usage.send(): Executes the sending process.
class Sender
{
private static $instance = null;
public static function getInstance(): Sender
{
if (!File::exists(config_path('sms.php'))) {
throw new RenderException("missing config/sms.php...");
}
if (!isset(self::$instance)) {
self::$instance = new self;
}
return self::$instance;
}
}