Symfony\Component\Console\Application::register PHP Method

register() public method

Registers a new command.
public register ( string $name ) : Command
$name string The command name
return Symfony\Component\Console\Command\Command The newly created command
    public function register($name)
    {
        return $this->add(new Command($name));
    }

Usage Example

 public function initTool()
 {
     $kernel = $this->container->get('kernel');
     $this->console = new Application($kernel);
     $this->console->setAutoExit(false);
     $this->console->setCatchExceptions(false);
     $this->console->add(new GenerateEntitiesDoctrineCommand());
     $this->console->add(new ConvertMappingDoctrineCommand());
     $self = $this;
     $this->console->register('rm')->setDefinition([new InputArgument('path', InputArgument::REQUIRED)])->setCode(function (InputInterface $input, OutputInterface $output) use($self) {
         $path = $input->getArgument('path');
         $cmd = 'rm -rf ' . $path . ' 2>&1';
         $output->writeln(sprintf('<comment>%s</comment>', $cmd));
         $self->runCmd($cmd, $output);
     });
     $this->console->register('mkdir')->setDefinition([new InputArgument('path', InputArgument::REQUIRED)])->setCode(function (InputInterface $input, OutputInterface $output) use($self) {
         $path = $input->getArgument('path');
         $cmd = 'mkdir ' . $path . ' 2>&1';
         $output->writeln(sprintf('<comment>%s</comment>', $cmd));
         $self->runCmd($cmd, $output);
     });
 }
All Usage Examples Of Symfony\Component\Console\Application::register