Cilex\Application::command PHP Method

command() public method

Allows you to add a command as Command object or as a command name+callable
public command ( string | Command $nameOrCommand, callable | null $callable = null ) : Command
$nameOrCommand string | Symfony\Component\Console\Command\Command
$callable callable | null Must be a callable if $nameOrCommand is the command's name
return Symfony\Component\Console\Command\Command The command instance that you can further configure
    public function command($nameOrCommand, $callable = null)
    {
        if ($nameOrCommand instanceof Command) {
            $command = $nameOrCommand;
        } else {
            if (!is_callable($callable)) {
                throw new \InvalidArgumentException('$callable must be a valid callable with the command\'s code');
            }
            $command = new Command($nameOrCommand);
            $command->setCode($callable);
        }
        $this['console']->add($command);
        return $command;
    }

Usage Example

Example #1
0
 /**
  * Tests the command method to see if the command is properly set and the
  * Cilex application is added as container.
  */
 public function testCommand()
 {
     $this->assertFalse($this->fixture['console']->has('demo:greet'));
     $this->fixture->command(new \Cilex\Command\GreetCommand());
     $this->assertTrue($this->fixture['console']->has('demo:greet'));
     $this->assertSame($this->fixture, $this->fixture['console']->get('demo:greet')->getContainer());
 }
All Usage Examples Of Cilex\Application::command