Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Command.php

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

InvalidArgumentException

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\Command

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal