Overview

Namespaces

  • Webmozart
    • Console
      • Adapter
      • Api
        • Application
        • Args
          • Format
        • Command
        • Config
        • Event
        • Formatter
        • IO
        • Resolver
      • Args
      • Config
      • Formatter
      • Handler
        • Help
      • IO
        • InputStream
        • OutputStream
      • Process
      • Resolver
      • UI
        • Alignment
        • Component
        • Help
        • Layout
        • Style
      • Util

Classes

  • CallbackHandler
  • DelegatingHandler
  • NullHandler
  • Overview
  • Namespace
  • Class

Class DelegatingHandler

Delegates command handling to one of a list of registered handlers.

You can register handlers or factory callbacks that create those handlers with the Webmozart\Console\Handler\DelegatingHandler::register() method:

$handler = new DelegatingHandler();
$handler->register('json', new JsonHandler());
$handler->register('xml', function () { $handler = new XmlHandler(); // ...
 return $handler;
});

The executed handler can be selected with Webmozart\Console\Handler\DelegatingHandler::selectHandler(). You need to pass the name of the handler or a callback that receives the command, the console arguments and the I/O as parameters:

$handler->selectHandler(function (Command $command, Args $args, IO $io) { return $args->getOption('format');
});

Run Webmozart\Console\Handler\DelegatingHandler::handle() to execute the selected handler:

$handler->handle($command, $args, $io);

Direct known subclasses

Webmozart\Console\Handler\Help\HelpHandler
Namespace: Webmozart\Console\Handler
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
Located at Handler/DelegatingHandler.php
Methods summary
public
# handle( Webmozart\Console\Api\Args\Args $args, Webmozart\Console\Api\IO\IO $io, Webmozart\Console\Api\Command\Command $command )
public
# register( string $name, object|callable $handler )

Registers a command handler for the given name.

Registers a command handler for the given name.

Parameters

$name
The handler name.
$handler

The handler or a factory callback that creates the handler.

public
# unregister( string $name )

Unregisters the command handler for the given name.

Unregisters the command handler for the given name.

Parameters

$name
The handler name.
public string[]
# getRegisteredNames( )

Returns all registered handler names.

Returns all registered handler names.

Returns

string[]
The handler names.
public
# selectHandler( string|callable $handler )

Selects the executed handler.

Selects the executed handler.

Parameters

$handler

The name of the handler or a callback that returns the name. The callback receives the executed Webmozart\Console\Api\Command\Command, the Webmozart\Console\Api\Args\Args and the Webmozart\Console\Api\IO\IO as arguments.

Webmozart Console API API documentation generated by ApiGen