New in design patterns and looking for the best design pattern for adding two gateways for sending SMS. Some messages should send with the first gateway and some with the second gateway. Also I want to put the gateway configs in .env
file.
Anyway here is my idea:
App\Services\Contracts
interface SMSGateway
{
public function send($message, $mobile);
}
App\Services
class FirstSMSGatewayService implements SMSGateway
{
function __construct($config)
{
// config
}
public function send($message, $mobile)
{
//
}
}
App\Services
class SecondSMSGatewayService implements SMSGateway
{
function __construct($config)
{
// config
}
public function send($message, $mobile)
{
//
}
}
App\Providers
class SMSGatewayProvider
{
$this->app->bind('App\Services\FirstSMSGatewayService', function () {
return new \App\Services\FirstSMSGatewayService(config('first-gateway'));
});
$this->app->bind('App\Services\SecondSMSGatewayService', function () {
return new \App\Services\SecondSMSGatewayService(config('first-gateway'));
});
}
Like simple factory
App\Jobs
class SendSMS implements ShouldQueue
{
__cuonstruct($message, $mobile, $gateway) {
if ($gateway == 'FirstGateway')
$this->sender = App\Services\FirstSMSGatewayService()
else
$this->sender = App\Services\SecondSMSGatewayService()
}
}
Aucun commentaire:
Enregistrer un commentaire