PHP Класс Webmozart\Console\Handler\DelegatingHandler

You can register handlers or factory callbacks that create those handlers with the {@link register()} method: php $handler = new DelegatingHandler(); $handler->register('json', new JsonHandler()); $handler->register('xml', function () { $handler = new XmlHandler(); ... return $handler; }); The executed handler can be selected with {@link 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: php $handler->selectHandler(function (Command $command, Args $args, IO $io) { return $args->getOption('format'); }); Run {@link handle()} to execute the selected handler: php $handler->handle($command, $args, $io);
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
getRegisteredNames ( ) : string[] Returns all registered handler names.
handle ( Args $args, IO $io, Command $command )
register ( string $name, object | callable $handler ) Registers a command handler for the given name.
selectHandler ( string | callback $handler ) Selects the executed handler.
unregister ( string $name ) Unregisters the command handler for the given name.

Описание методов

getRegisteredNames() публичный Метод

Returns all registered handler names.
public getRegisteredNames ( ) : string[]
Результат string[] The handler names.

handle() публичный Метод

public handle ( Args $args, IO $io, Command $command )
$args Webmozart\Console\Api\Args\Args
$io Webmozart\Console\Api\IO\IO
$command Webmozart\Console\Api\Command\Command

register() публичный Метод

Registers a command handler for the given name.
public register ( string $name, object | callable $handler )
$name string The handler name.
$handler object | callable The handler or a factory callback that creates the handler.

selectHandler() публичный Метод

Selects the executed handler.
public selectHandler ( string | callback $handler )
$handler string | callback The name of the handler or a callback that returns the name. The callback receives the executed {@link Command}, the {@link Args} and the {@link IO} as arguments.

unregister() публичный Метод

Unregisters the command handler for the given name.
public unregister ( string $name )
$name string The handler name.