HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: //proc/self/cwd/nueva/vendor/league/tactician-bundle/src/Handler/ContainerBasedHandlerLocator.php
<?php

namespace League\Tactician\Bundle\Handler;

use League\Tactician\Exception\MissingHandlerException;
use League\Tactician\Handler\Locator\HandlerLocator;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Lazily loads Command Handlers from the Symfony DI container
 */
class ContainerBasedHandlerLocator implements HandlerLocator
{
    /**
     * @var ContainerInterface
     */
    private $container;

    /**
     * @var array
     */
    private $commandToServiceId = [];

    /**
     * @param ContainerInterface $container
     * @param array $commandToServiceIdMapping
     */
    public function __construct(ContainerInterface $container, array $commandToServiceIdMapping)
    {
        $this->container = $container;
        $this->commandToServiceId = $commandToServiceIdMapping;
    }

    /**
     * Retrieves the handler for a specified command
     *
     * @param string $commandName
     * @return object
     *
     * @throws MissingHandlerException
     */
    public function getHandlerForCommand($commandName)
    {
        if (!isset($this->commandToServiceId[$commandName])) {
            throw MissingHandlerException::forCommand($commandName);
        }

        return $this->container->get($this->commandToServiceId[$commandName]);
    }
}