Webmozart\Console\Api\Config\Config::setHandler PHP Method

setHandler() public method

You can pass: * An object with handler methods. * A callable that receives a {@link Command} and returns an object with handler methods. The name of the executed handler method can be configured with {@link setHandlerMethod()}. By default, the method handle() is executed.
See also: getHandler()
public setHandler ( object | callback $handler ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$handler object | callback The command handler or the callable creating a new command handler on demand.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.
    public function setHandler($handler)
    {
        if (!is_object($handler) && !is_callable($handler)) {
            throw new InvalidArgumentException(sprintf('Expected an object or a callable. Got: %s', is_object($handler) ? get_class($handler) : gettype($handler)));
        }
        $this->handler = $handler;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetHandlerFailsIfNeitherObjectNorCallable()
 {
     $this->config->setHandler(1234);
 }