VoiceCallAuditLogResolver.php 1.62 KB
<?php

namespace NexmoBundle\Event\Logger;

use AppBundle\Entity\User;
use AppBundle\Event\VoiceCallEvents;
use Chromedia\AuditLogBundle\Resolver\EventResolverInterface;
use NexmoBundle\Event\Logger\Command\InboundVoiceCallCommand;
use NexmoBundle\Event\Logger\Command\UpdateVoiceCallStatusCommand;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;

class VoiceCallAuditLogResolver implements EventResolverInterface
{
    protected $commands;

    /**
     * @var TokenStorage
     */
    protected $tokenStorage;

    public function __construct()
    {
        $this->commands = [
            VoiceCallEvents::COMPLETED_VOICE_CALL => UpdateVoiceCallStatusCommand::class,
            VoiceCallEvents::FAILED_VOICE_CALL => UpdateVoiceCallStatusCommand::class,
            VoiceCallEvents::STARTED_VOICE_CALL => UpdateVoiceCallStatusCommand::class,
            VoiceCallEvents::INBOUND_CALL_ONGOING => InboundVoiceCallCommand::class,
            VoiceCallEvents::INBOUND_CALL_COMPLETED => InboundVoiceCallCommand::class
        ];
    }

    public function setTokenStorage(TokenStorage $v)
    {
        $this->tokenStorage = $v;
    }

    /**
     * @param Event  $event
     * @param string $eventName
     * @return mixed
     */
    public function getEventLogInfo(Event $event, $eventName)
    {
        if (!isset($this->commands[$eventName])) {
            return;
        }

        $class = $this->commands[$eventName];
        $command = new $class();
        if ($command instanceof VoiceCallAuditLogCommand) {
            return $command->resolve($event);
        }
    }
}