Symfony\Component\Console\Command\Command::setCode PHP Method

setCode() public method

If this method is used, it overrides the code defined in the execute() method.
See also: execute()
public setCode ( callable $code ) : Command
$code callable A callable(InputInterface $input, OutputInterface $output)
return Command The current instance
    public function setCode(callable $code)
    {
        if ($code instanceof \Closure) {
            $r = new \ReflectionFunction($code);
            if (null === $r->getClosureThis()) {
                if (PHP_VERSION_ID < 70000) {
                    // Bug in PHP5: https://bugs.php.net/bug.php?id=64761
                    // This means that we cannot bind static closures and therefore we must
                    // ignore any errors here.  There is no way to test if the closure is
                    // bindable.
                    $code = @\Closure::bind($code, $this);
                } else {
                    $code = \Closure::bind($code, $this);
                }
            }
        }
        $this->code = $code;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @dataProvider inputInteractiveCommandToOutputFilesProvider
  */
 public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
 {
     $code = (require $inputCommandFilepath);
     $this->command->setCode($code);
     $this->tester->execute(array(), array('interactive' => true, 'decorated' => false));
     $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
 }
All Usage Examples Of Symfony\Component\Console\Command\Command::setCode