示例#1
0
 /**
  * Check for an alias and replace the input with a new string command
  * if the alias exists.
  *
  * @return string New command string (for testing purposes)
  */
 public function handleAlias(CommandPreRunEvent $event)
 {
     $input = $event->getInput();
     $commandName = $input->getFirstArgument();
     $aliasConfig = $this->configManager->getConfig('alias');
     if (!isset($aliasConfig[$commandName])) {
         return;
     }
     $commandTemplate = $aliasConfig[$commandName];
     $replaces = array();
     preg_match_all('{\\{arg[0-9]+\\}}', $commandTemplate, $matches);
     $args = array();
     if (isset($matches[0])) {
         $args = $matches[0];
     }
     $tokens = $input->getTokens();
     foreach ($tokens as $i => $token) {
         if (strstr($token, ' ')) {
             $token = escapeshellarg($token);
         }
         $replaces['{arg' . $i . '}'] = $token;
     }
     $command = strtr($commandTemplate, $replaces);
     foreach ($args as $arg) {
         $command = str_replace($arg, '', $command);
     }
     $command = trim($command);
     $newInput = new StringInput($command);
     $event->setInput($newInput);
     return $command;
 }
示例#2
0
 public function it_should_ommit_missing_arguments(CommandPreRunEvent $event, StringInput $input)
 {
     $event->getInput()->willReturn($input);
     $input->getFirstArgument()->willReturn('ls');
     $input->getTokens()->willReturn(array('ls'));
     $event->setInput(Argument::type('PHPCR\\Shell\\Console\\Input\\StringInput'))->shouldBeCalled();
     $this->handleAlias($event)->shouldReturn('list:command');
 }
示例#3
0
 public function it_should_convert_an_aliased_input_into_a_real_command_input(CommandPreRunEvent $event, StringInput $input)
 {
     $event->getInput()->willReturn($input);
     $input->getRawCommand()->willReturn('ls -L5 --children');
     $input->getFirstArgument()->willReturn('ls');
     $event->setInput(Argument::type('PHPCR\\Shell\\Console\\Input\\StringInput'))->shouldBeCalled();
     $this->handleAlias($event)->shouldReturn('list:command -L5 --children');
 }
示例#4
0
 /**
  * Check for an alias and replace the input with a new string command
  * if the alias exists.
  *
  * @return string New command string (for testing purposes)
  */
 public function handleAlias(CommandPreRunEvent $event)
 {
     $input = $event->getInput();
     $commandName = $input->getFirstArgument();
     $aliasConfig = $this->configManager->getConfig('alias');
     if (!isset($aliasConfig[$commandName])) {
         return;
     }
     $command = $aliasConfig[$commandName];
     $command = $command .= substr($input->getRawCommand(), strlen($commandName));
     $newInput = new StringInput($command);
     $event->setInput($newInput);
     return $command;
 }