Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace IctWorks\Messaging\Application\Conversation\Subscriber;
- use IctWorks\Messaging\Domain\Conversation\ConversationRepository;
- use IctWorks\Messaging\Domain\Message\Event\MessageWasSent;
- use IctWorks\Messaging\Infrastructure\MessagingProvider\MessagingProviderChoosingService;
- use IctWorks\SharedKernel\Application\EventSubscriber;
- use IctWorks\SharedKernel\Domain\Event\DomainMessage;
- use IctWorks\SharedKernel\Domain\Service\TimeService;
- use JMS\DiExtraBundle\Annotation as DI;
- use Webmozart\Assert\Assert;
- /**
- * Class ChangeLastSeenDateWhenMessageWasSent
- * @package IctWorks\Messaging\Application\Conversation\Subscriber
- * @author Dariusz Gafka <dgafka.mail@gmail.com>
- *
- * @DI\Service()
- * @DI\Tag("event_subscriber", attributes={
- * "subscribes_to"=MessageWasSent::class
- * })
- */
- class ChangeLastSeenDateWhenMessageWasSent implements EventSubscriber
- {
- /** @var ConversationRepository */
- private $conversationRepository;
- /**
- * @var MessagingProviderChoosingService
- */
- private $messagingProviderChoosingService;
- /**
- * @var TimeService
- */
- private $timeService;
- /**
- * MarkConversationAsResolvedCommandHandler constructor.
- *
- * @param ConversationRepository $conversationRepository
- *
- * @param MessagingProviderChoosingService $messagingProviderChoosingService
- * @param TimeService $timeService
- * @DI\InjectParams({
- * "conversationRepository" = @DI\Inject("ict_works.messaging.domain.conversation.conversation_repository"),
- * "messagingProviderChoosingService" =
- * @DI\Inject("ict_works.messaging.infrastructure.messaging_provider.messaging_provider_choosing_service"),
- * "timeService" = @DI\Inject("ict_works.shared_kernel.domain.service.time_service")
- * })
- */
- public function __construct(ConversationRepository $conversationRepository, MessagingProviderChoosingService $messagingProviderChoosingService, TimeService $timeService)
- {
- $this->conversationRepository = $conversationRepository;
- $this->messagingProviderChoosingService = $messagingProviderChoosingService;
- $this->timeService = $timeService;
- }
- /**
- * @inheritDoc
- */
- public function handle(DomainMessage $domainMessage)
- {
- die("event!");
- /** @var MessageWasSent $domainMessage */
- Assert::isInstanceOf($domainMessage, MessageWasSent::class);
- $conversation = $this->conversationRepository->byConversationId($domainMessage->conversationId());
- $conversation->markAsSeen($this->timeService);
- $this->conversationRepository->save($conversation);
- }
- /**
- * @inheritDoc
- */
- public function subscribesTo()
- {
- return MessageWasSent::class;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement