function Command::setCode
Sets the code to execute when running this command.
If this method is used, it overrides the code defined in the execute() method.
Parameters
callable $code A callable(InputInterface $input, OutputInterface $output):
Return value
$this
Throws
See also
execute()
2 calls to Command::setCode()
- TraceableCommand::setCode in vendor/
symfony/ console/ Command/ TraceableCommand.php - Calling parent method is required to be used in {
- TraceableCommand::setCode in vendor/
symfony/ console/ Command/ TraceableCommand.php - Calling parent method is required to be used in {
2 methods override Command::setCode()
- LazyCommand::setCode in vendor/
symfony/ console/ Command/ LazyCommand.php - Sets the code to execute when running this command.
- TraceableCommand::setCode in vendor/
symfony/ console/ Command/ TraceableCommand.php - Calling parent method is required to be used in {
File
-
vendor/
symfony/ console/ Command/ Command.php, line 312
Class
- Command
- Base class for all commands.
Namespace
Symfony\Component\Console\CommandCode
public function setCode(callable $code) : static {
if ($code instanceof \Closure) {
$r = new \ReflectionFunction($code);
if (null === $r->getClosureThis()) {
set_error_handler(static function () {
});
try {
if ($c = \Closure::bind($code, $this)) {
$code = $c;
}
} finally {
restore_error_handler();
}
}
}
else {
$code = $code(...);
}
$this->code = $code;
return $this;
}