CoreFiles by mySites.guru
CommandCompletionTester.php56 lines, 1,544 bytes, from Joomla_5.2.6-Stable-Full_Package.zip
Raw History Compare with 5.2.5
md5
6c729e278d26d4afbe3d42cc639cbe0f
sha1
72680a0e2da0ca6be3c819d34f19ba8e94c0df05
sha256
aef2a32921a8bca1e803bd970d941ff3cd426976bc30d39e0ec1f921fdf74112
<?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\Tester;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;

/**
 * Eases the testing of command completion.
 *
 * @author Jérôme Tamarelle <[email protected]>
 */
class CommandCompletionTester
{
    private Command $command;

    public function __construct(Command $command)
    {
        $this->command = $command;
    }

    /**
     * Create completion suggestions from input tokens.
     */
    public function complete(array $input): array
    {
        $currentIndex = \count($input);
        if ('' === end($input)) {
            array_pop($input);
        }
        array_unshift($input, $this->command->getName());

        $completionInput = CompletionInput::fromTokens($input, $currentIndex);
        $completionInput->bind($this->command->getDefinition());
        $suggestions = new CompletionSuggestions();

        $this->command->complete($completionInput, $suggestions);

        $options = [];
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $options[] = '--'.$option->getName();
        }

        return array_map('strval', array_merge($options, $suggestions->getValueSuggestions()));
    }
}

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