N98\Magento\Application\Config::checkConfigCommandAlias PHP Method

checkConfigCommandAlias() public method

alias magerun command in input from config
public checkConfigCommandAlias ( Symfony\Component\Console\Input\InputInterface $input ) : Symfony\Component\Console\Input\ArgvInput | Symfony\Component\Console\Input\InputInterface
$input Symfony\Component\Console\Input\InputInterface
return Symfony\Component\Console\Input\ArgvInput | Symfony\Component\Console\Input\InputInterface
    public function checkConfigCommandAlias(InputInterface $input)
    {
        foreach ($this->getArray(array('commands', 'aliases')) as $alias) {
            if (!is_array($alias)) {
                continue;
            }
            $aliasCommandName = key($alias);
            if ($input->getFirstArgument() !== $aliasCommandName) {
                continue;
            }
            $aliasCommandParams = array_slice(BinaryString::trimExplodeEmpty(' ', $alias[$aliasCommandName]), 1);
            if (0 === count($aliasCommandParams)) {
                continue;
            }
            // replace command (?) with aliased data
            $oldArgv = $_SERVER['argv'];
            $newArgv = array_merge(array_slice($oldArgv, 0, 2), $aliasCommandParams, array_slice($oldArgv, 2));
            $input = new ArgvInput($newArgv);
        }
        return $input;
    }

Usage Example

Example #1
0
 /**
  * @test
  */
 public function configCommandAlias()
 {
     $config = new Config();
     $input = new ArgvInput();
     $actual = $config->checkConfigCommandAlias($input);
     $this->assertInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface', $actual);
     $saved = $_SERVER['argv'];
     $config->setConfig(array('commands' => array('aliases' => array(array('list-help' => 'list --help')))));
     $definition = new InputDefinition();
     $definition->addArgument(new InputArgument('command'));
     $argv = array('/path/to/command', 'list-help');
     $_SERVER['argv'] = $argv;
     $input = new ArgvInput($argv, $definition);
     $this->assertSame('list-help', (string) $input);
     $actual = $config->checkConfigCommandAlias($input);
     $this->assertSame('list-help', $actual->getFirstArgument());
     $this->assertSame('list-help --help', (string) $actual);
     $_SERVER['argv'] = $saved;
     $command = new Command('list');
     $config->registerConfigCommandAlias($command);
     $this->assertSame(array('list-help'), $command->getAliases());
 }
All Usage Examples Of N98\Magento\Application\Config::checkConfigCommandAlias