Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace frontendBiglion\api\versions\v4\application\lead;
- use frontend\domain\client\ClientRepositoryInterface;
- use frontend\infrastructure\factories\client\ARClientFactoryInterface;
- use frontend\application\auth\ClientAuthServiceInterface;
- use frontendBiglion\api\versions\v4\application\lead\strategy\DelayedCommunicateStrategy;
- use frontendBiglion\api\versions\v4\application\lead\strategy\DelayedSaveStrategy;
- use frontendBiglion\api\versions\v4\application\lead\strategy\StraightCommunicateStrategy;
- use frontendBiglion\api\versions\v4\application\lead\strategy\StraightSaveStrategy;
- use frontendBiglion\api\versions\v4\domain\lead\PromoLeadEmailRepositoryInterface;
- use frontendBiglion\api\versions\v4\domain\lead\PromoLeadRepositoryInterface;
- use frontendBiglion\api\versions\v4\infrastructure\persistence\mappers\hydrator\lead\PromoLeadEmailMapper;
- use frontendBiglion\api\versions\v4\infrastructure\persistence\mappers\hydrator\lead\PromoLeadMapper;
- use frontendBiglion\api\versions\v4\infrastructure\persistence\repositories\yiiConnection\lead\PromoLeadRepository;
- /**
- * Сервис для работы с лидами
- */
- class PromoLeadService implements PromoLeadServiceInterface
- {
- /**
- * @var ClientRepositoryInterface
- */
- private $clientRepository;
- /**
- * @var ARClientFactoryInterface
- */
- private $clientFactory;
- /**
- * @var ClientAuthServiceInterface
- */
- private $clientAuthService;
- /**
- * @var PromoLeadMapper
- */
- private $promoLeadMapper;
- /**
- * @var PromoLeadRepository
- */
- private $promoLeadRepository;
- /**
- * @var PromoLeadEmailMapper
- */
- private $promoLeadEmailMapper;
- /**
- * @var PromoLeadEmailRepositoryInterface
- */
- private $promoLeadEmailRepository;
- /**
- * SaveLidAction constructor.
- * @param ClientRepositoryInterface $clientRepository
- * @param ARClientFactoryInterface $clientFactory
- * @param ClientAuthServiceInterface $clientAuthService
- * @param PromoLeadMapper $promoLeadMapper
- * @param PromoLeadRepositoryInterface $promoLeadRepository
- * @param PromoLeadEmailMapper $promoLeadEmailMapper
- * @param PromoLeadEmailRepositoryInterface $promoLeadEmailRepository
- */
- public function __construct(
- ClientRepositoryInterface $clientRepository,
- ARClientFactoryInterface $clientFactory,
- ClientAuthServiceInterface $clientAuthService,
- PromoLeadMapper $promoLeadMapper,
- PromoLeadRepositoryInterface $promoLeadRepository,
- PromoLeadEmailMapper $promoLeadEmailMapper,
- PromoLeadEmailRepositoryInterface $promoLeadEmailRepository
- ) {
- $this->clientRepository = $clientRepository;
- $this->clientFactory = $clientFactory;
- $this->clientAuthService = $clientAuthService;
- $this->promoLeadMapper = $promoLeadMapper;
- $this->promoLeadRepository = $promoLeadRepository;
- $this->promoLeadEmailMapper = $promoLeadEmailMapper;
- $this->promoLeadEmailRepository = $promoLeadEmailRepository;
- }
- /**
- * @inheritdoc
- */
- public function processLeadRequestDto(PromoLeadRequestDto $leadRequestDto)
- {
- $strategy = $leadRequestDto->strategy;
- $lead = $this
- ->getCommunicateStrategy($strategy)
- ->create($leadRequestDto);
- return $this
- ->getSaveStrategy($strategy)
- ->save($lead);
- }
- private function getSaveStrategy($strategy)
- {
- switch ($strategy) {
- case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_STRAIGHT:
- return new StraightSaveStrategy(
- $this->promoLeadRepository
- );
- case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_DELAYED:
- return new DelayedSaveStrategy(
- $this->promoLeadEmailRepository
- );
- }
- }
- private function getCommunicateStrategy($strategy)
- {
- switch ($strategy) {
- case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_STRAIGHT:
- return new StraightCommunicateStrategy(
- $this->clientRepository,
- $this->clientFactory,
- $this->clientAuthService,
- $this->promoLeadMapper
- );
- case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_DELAYED:
- return new DelayedCommunicateStrategy(
- $this->promoLeadEmailMapper
- );
- }
- }
- }
Add Comment
Please, Sign In to add comment