CoreFiles by mySites.guru
FactoryCommandLoader.php54 lines, 1,313 bytes, from Joomla_5.2.2-Stable-Full_Package.zip
Raw History Compare with 5.2.1
md5
e63e0a000667d549a0c594b1412dcd4d
sha1
9ad3a712e93d32962f21d933d7e217c6e5562d02
sha256
da470aa596fc986413e31a10a533b0bb8bb5ed0c3433f574a4a0481d64ffc664
<?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 Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\CommandNotFoundException;

/**
 * A simple command loader using factories to instantiate commands lazily.
 *
 * @author Maxime Steinhausser <[email protected]>
 */
class FactoryCommandLoader implements CommandLoaderInterface
{
    private array $factories;

    /**
     * @param callable[] $factories Indexed by command names
     */
    public function __construct(array $factories)
    {
        $this->factories = $factories;
    }

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

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

        $factory = $this->factories[$name];

        return $factory();
    }

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

The same content is in 85 releases, Joomla 5.0.0-alpha1 to 6.0.0-alpha3. See them all, or every version of this file.