Guest User

Untitled

a guest
Oct 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. <?php
  2.  
  3. namespace frontendBiglion\api\versions\v4\application\lead;
  4.  
  5. use frontend\domain\client\ClientRepositoryInterface;
  6. use frontend\infrastructure\factories\client\ARClientFactoryInterface;
  7. use frontend\application\auth\ClientAuthServiceInterface;
  8. use frontendBiglion\api\versions\v4\application\lead\strategy\DelayedCommunicateStrategy;
  9. use frontendBiglion\api\versions\v4\application\lead\strategy\DelayedSaveStrategy;
  10. use frontendBiglion\api\versions\v4\application\lead\strategy\StraightCommunicateStrategy;
  11. use frontendBiglion\api\versions\v4\application\lead\strategy\StraightSaveStrategy;
  12. use frontendBiglion\api\versions\v4\domain\lead\PromoLeadEmailRepositoryInterface;
  13. use frontendBiglion\api\versions\v4\domain\lead\PromoLeadRepositoryInterface;
  14. use frontendBiglion\api\versions\v4\infrastructure\persistence\mappers\hydrator\lead\PromoLeadEmailMapper;
  15. use frontendBiglion\api\versions\v4\infrastructure\persistence\mappers\hydrator\lead\PromoLeadMapper;
  16. use frontendBiglion\api\versions\v4\infrastructure\persistence\repositories\yiiConnection\lead\PromoLeadRepository;
  17.  
  18. /**
  19. * Сервис для работы с лидами
  20. */
  21. class PromoLeadService implements PromoLeadServiceInterface
  22. {
  23. /**
  24. * @var ClientRepositoryInterface
  25. */
  26. private $clientRepository;
  27.  
  28. /**
  29. * @var ARClientFactoryInterface
  30. */
  31. private $clientFactory;
  32.  
  33. /**
  34. * @var ClientAuthServiceInterface
  35. */
  36. private $clientAuthService;
  37.  
  38. /**
  39. * @var PromoLeadMapper
  40. */
  41. private $promoLeadMapper;
  42.  
  43. /**
  44. * @var PromoLeadRepository
  45. */
  46. private $promoLeadRepository;
  47.  
  48. /**
  49. * @var PromoLeadEmailMapper
  50. */
  51. private $promoLeadEmailMapper;
  52.  
  53. /**
  54. * @var PromoLeadEmailRepositoryInterface
  55. */
  56. private $promoLeadEmailRepository;
  57.  
  58. /**
  59. * SaveLidAction constructor.
  60. * @param ClientRepositoryInterface $clientRepository
  61. * @param ARClientFactoryInterface $clientFactory
  62. * @param ClientAuthServiceInterface $clientAuthService
  63. * @param PromoLeadMapper $promoLeadMapper
  64. * @param PromoLeadRepositoryInterface $promoLeadRepository
  65. * @param PromoLeadEmailMapper $promoLeadEmailMapper
  66. * @param PromoLeadEmailRepositoryInterface $promoLeadEmailRepository
  67. */
  68. public function __construct(
  69. ClientRepositoryInterface $clientRepository,
  70. ARClientFactoryInterface $clientFactory,
  71. ClientAuthServiceInterface $clientAuthService,
  72. PromoLeadMapper $promoLeadMapper,
  73. PromoLeadRepositoryInterface $promoLeadRepository,
  74. PromoLeadEmailMapper $promoLeadEmailMapper,
  75. PromoLeadEmailRepositoryInterface $promoLeadEmailRepository
  76. ) {
  77. $this->clientRepository = $clientRepository;
  78. $this->clientFactory = $clientFactory;
  79. $this->clientAuthService = $clientAuthService;
  80. $this->promoLeadMapper = $promoLeadMapper;
  81. $this->promoLeadRepository = $promoLeadRepository;
  82. $this->promoLeadEmailMapper = $promoLeadEmailMapper;
  83. $this->promoLeadEmailRepository = $promoLeadEmailRepository;
  84. }
  85.  
  86. /**
  87. * @inheritdoc
  88. */
  89. public function processLeadRequestDto(PromoLeadRequestDto $leadRequestDto)
  90. {
  91. $strategy = $leadRequestDto->strategy;
  92.  
  93. $lead = $this
  94. ->getCommunicateStrategy($strategy)
  95. ->create($leadRequestDto);
  96.  
  97. return $this
  98. ->getSaveStrategy($strategy)
  99. ->save($lead);
  100. }
  101.  
  102. private function getSaveStrategy($strategy)
  103. {
  104. switch ($strategy) {
  105. case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_STRAIGHT:
  106. return new StraightSaveStrategy(
  107. $this->promoLeadRepository
  108. );
  109. case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_DELAYED:
  110. return new DelayedSaveStrategy(
  111. $this->promoLeadEmailRepository
  112. );
  113. }
  114. }
  115.  
  116. private function getCommunicateStrategy($strategy)
  117. {
  118. switch ($strategy) {
  119. case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_STRAIGHT:
  120. return new StraightCommunicateStrategy(
  121. $this->clientRepository,
  122. $this->clientFactory,
  123. $this->clientAuthService,
  124. $this->promoLeadMapper
  125. );
  126. case PromoLeadServiceInterface::COMMUNICATE_STRATEGY_DELAYED:
  127. return new DelayedCommunicateStrategy(
  128. $this->promoLeadEmailMapper
  129. );
  130. }
  131. }
  132. }
Add Comment
Please, Sign In to add comment