Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.87 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. namespace IctWorks\Messaging\Application\Conversation\Subscriber;
  5.  
  6. use IctWorks\Messaging\Domain\Conversation\ConversationRepository;
  7. use IctWorks\Messaging\Domain\Message\Event\MessageWasSent;
  8. use IctWorks\Messaging\Infrastructure\MessagingProvider\MessagingProviderChoosingService;
  9. use IctWorks\SharedKernel\Application\EventSubscriber;
  10. use IctWorks\SharedKernel\Domain\Event\DomainMessage;
  11. use IctWorks\SharedKernel\Domain\Service\TimeService;
  12. use JMS\DiExtraBundle\Annotation as DI;
  13. use Webmozart\Assert\Assert;
  14.  
  15. /**
  16.  * Class ChangeLastSeenDateWhenMessageWasSent
  17.  * @package IctWorks\Messaging\Application\Conversation\Subscriber
  18.  * @author  Dariusz Gafka <dgafka.mail@gmail.com>
  19.  *
  20.  * @DI\Service()
  21.  * @DI\Tag("event_subscriber", attributes={
  22.  *     "subscribes_to"=MessageWasSent::class
  23.  * })
  24.  */
  25. class ChangeLastSeenDateWhenMessageWasSent implements EventSubscriber
  26. {
  27.     /** @var ConversationRepository */
  28.     private $conversationRepository;
  29.     /**
  30.      * @var MessagingProviderChoosingService
  31.      */
  32.     private $messagingProviderChoosingService;
  33.     /**
  34.      * @var TimeService
  35.      */
  36.     private $timeService;
  37.  
  38.     /**
  39.      * MarkConversationAsResolvedCommandHandler constructor.
  40.      *
  41.      * @param ConversationRepository           $conversationRepository
  42.      *
  43.      * @param MessagingProviderChoosingService $messagingProviderChoosingService
  44.      * @param TimeService                      $timeService
  45.      * @DI\InjectParams({
  46.      *     "conversationRepository" = @DI\Inject("ict_works.messaging.domain.conversation.conversation_repository"),
  47.      *     "messagingProviderChoosingService" =
  48.      *     @DI\Inject("ict_works.messaging.infrastructure.messaging_provider.messaging_provider_choosing_service"),
  49.      *     "timeService"            = @DI\Inject("ict_works.shared_kernel.domain.service.time_service")
  50.      * })
  51.      */
  52.     public function __construct(ConversationRepository $conversationRepository, MessagingProviderChoosingService $messagingProviderChoosingService, TimeService $timeService)
  53.     {
  54.         $this->conversationRepository           = $conversationRepository;
  55.         $this->messagingProviderChoosingService = $messagingProviderChoosingService;
  56.         $this->timeService                      = $timeService;
  57.     }
  58.  
  59.  
  60.     /**
  61.      * @inheritDoc
  62.      */
  63.     public function handle(DomainMessage $domainMessage)
  64.     {
  65.         die("event!");
  66.         /** @var MessageWasSent $domainMessage */
  67.         Assert::isInstanceOf($domainMessage, MessageWasSent::class);
  68.  
  69.         $conversation = $this->conversationRepository->byConversationId($domainMessage->conversationId());
  70.         $conversation->markAsSeen($this->timeService);
  71.         $this->conversationRepository->save($conversation);
  72.     }
  73.  
  74.     /**
  75.      * @inheritDoc
  76.      */
  77.     public function subscribesTo()
  78.     {
  79.         return MessageWasSent::class;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement