CoreFiles by mySites.guru
ContainerCommandLoader.php52 lines, 1,370 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
4e8ce17a0c9c6fb995046c49ea2230d1
sha1
a37f2b5fc3382807944728da0d31b1f929a1ebb2
sha256
9ab3b3a463936300dcdd116e09df879634a87954fbeaeb86b7f4d53c66c67563
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\CommandLoader;

use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\CommandNotFoundException;

/**
 * Loads commands from a PSR-11 container.
 *
 * @author Robin Chalas <[email protected]>
 */
class ContainerCommandLoader implements CommandLoaderInterface
{
    /**
     * @param array $commandMap An array with command names as keys and service ids as values
     */
    public function __construct(
        private ContainerInterface $container,
        private array $commandMap,
    ) {
    }

    public function get(string $name): Command
    {
        if (!$this->has($name)) {
            throw new CommandNotFoundException(\sprintf('Command "%s" does not exist.', $name));
        }

        return $this->container->get($this->commandMap[$name]);
    }

    public function has(string $name): bool
    {
        return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
    }

    public function getNames(): array
    {
        return array_keys($this->commandMap);
    }
}

The same content is in 48 releases, Joomla 6.0.0-beta1 to 6.2.1. See them all, or every version of this file.