Created
November 22, 2018 09:26
-
-
Save BerezhniyDmitro/d51292185c1c608544610132194eb19d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Module\Sender\Factory; | |
use InvalidArgumentException; | |
use App\Module\Sender\ChannelServiceProvider\ChannelsServiceProvider; | |
use App\Module\Sender\Interfaces\IMessage; | |
use App\Module\Sender\Manager\EmailManagerService; | |
use App\Module\Sender\Manager\ViberManagerService; | |
/** | |
* Class ManagersFactory фабрика сервисов рассылки | |
*/ | |
class ManagersServiceFactory | |
{ | |
/** | |
* Метод создает набор сервисов отправки | |
* | |
* @param array $availableChannelManagers массив обработчиков | |
* @param IMessage $message отправляемое письмо | |
* | |
* @return array | |
*/ | |
public function createDispatchManagers(array $availableChannelManagers, IMessage $message) | |
{ | |
if (empty($availableChannelManagers)) { | |
return []; | |
} | |
$managers = []; | |
foreach ($availableChannelManagers as $nameChannel => $availableChannelManager) { | |
if ($nameChannel === EmailManagerService::EMAIL) { | |
$managers[] = new $availableChannelManager($message); | |
continue; | |
} | |
if ($nameChannel === ViberManagerService::VIBER) { | |
$managers[] = new $availableChannelManager($message); | |
continue; | |
} | |
if ($nameChannel === TelegrammManagerService::TELEGRAMM) { | |
$managers[] = new $availableChannelManager($message); | |
continue; | |
} | |
throw new InvalidArgumentException( | |
sprintf( | |
'Передан неизвестный тип канала отправки %s Реализуйте его и добавьте в %s', | |
$nameChannel, | |
ChannelsServiceProvider::class | |
) | |
); | |
} | |
return $managers; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment