class HookManager implements EventSubscriberInterface (View source)

Manage named callback hooks

Constants

REPLACE_COMMAND_HOOK

PRE_COMMAND_EVENT

COMMAND_EVENT

POST_COMMAND_EVENT

PRE_OPTION_HOOK

OPTION_HOOK

POST_OPTION_HOOK

PRE_INITIALIZE

INITIALIZE

POST_INITIALIZE

PRE_INTERACT

INTERACT

POST_INTERACT

PRE_ARGUMENT_VALIDATOR

ARGUMENT_VALIDATOR

POST_ARGUMENT_VALIDATOR

PRE_COMMAND_HOOK

COMMAND_HOOK

POST_COMMAND_HOOK

PRE_PROCESS_RESULT

PROCESS_RESULT

POST_PROCESS_RESULT

PRE_ALTER_RESULT

ALTER_RESULT

POST_ALTER_RESULT

STATUS_DETERMINER

EXTRACT_OUTPUT

ON_EVENT

Properties

protected $hooks
protected $hookOptions

var CommandInfo[]

Methods

__construct()

No description

getAllHooks()

No description

add(callable $callback, string $hook, string $name = '*')

Add a hook

recordHookOptions($commandInfo, $name)

No description

static 
getNames($command, $callback)

No description

static 
getNamesUsingCommands($command)

No description

static 
getClassNameFromCallback($callback)

If a command hook does not specify any particular command name that it should be attached to, then it will be applied to every command that is defined in the same class as the hook.

addReplaceCommandHook(ReplaceCommandHookInterface $replaceCommandHook, $name)

Add a replace command hook

addPreCommandEventDispatcher(EventDispatcherInterface $eventDispatcher, $name = '*')

No description

addCommandEventDispatcher(EventDispatcherInterface $eventDispatcher, $name = '*')

No description

addPostCommandEventDispatcher(EventDispatcherInterface $eventDispatcher, $name = '*')

No description

addCommandEvent(EventSubscriberInterface $eventSubscriber)

No description

addInitializeHook(InitializeHookInterface $initializeHook, type $name = '*')

Add an configuration provider hook

addOptionHook(OptionHookInterface $interactor, type $name = '*')

Add an option hook

addInteractor(InteractorInterface $interactor, type $name = '*')

Add an interact hook

addPreValidator(ValidatorInterface $validator, type $name = '*')

Add a pre-validator hook

addValidator(ValidatorInterface $validator, type $name = '*')

Add a validator hook

addPreCommandHook(ValidatorInterface $preCommand, type $name = '*')

Add a pre-command hook. This is the same as a validator hook, except that it will run after all of the post-validator hooks.

addPostCommandHook(ProcessResultInterface $postCommand, type $name = '*')

Add a post-command hook. This is the same as a pre-process hook, except that it will run before the first pre-process hook.

addResultProcessor(ProcessResultInterface $resultProcessor, type $name = '*')

Add a result processor.

addAlterResult(AlterResultInterface $resultAlterer, type $name = '*')

Add a result alterer. After a result is processed by a result processor, an alter hook may be used to convert the result from one form to another.

addStatusDeterminer(StatusDeterminerInterface $statusDeterminer, type $name = '*')

Add a status determiner. Usually, a command should return an integer on error, or a result object on success (which implies a status code of zero). If a result contains the status code in some other field, then a status determiner can be used to call the appropriate accessor method to determine the status code. This is usually not necessary, though; a command that fails may return a CommandError object, which contains a status code and a result message to display.

addOutputExtractor(ExtractOutputInterface $outputExtractor, type $name = '*')

Add an output extractor. If a command returns an object object, by default it is passed directly to the output formatter (if in use) for rendering. If the result object contains more information than just the data to render, though, then an output extractor can be used to call the appopriate accessor method of the result object to get the data to rendered. This is usually not necessary, though; it is preferable to have complex result objects implement the OutputDataInterface.

getHookOptionsForCommand($command)

No description

CommandInfo[]
getHookOptions($names)

No description

callable[]
getHooks(string|array $names, string[] $hooks, $annotationData = null)

Get a set of hooks with the provided name(s). Include the pre- and post- hooks, and also include the global hooks ('*') in addition to the named hooks provided.

addWildcardHooksToNames($names, $annotationData = null)

No description

callable[]
get(string|array $names, string[] $hooks)

Get a set of hooks with the provided name(s).

callable[]
getHook(string $name, string $hook)

Get a single named hook.

callCommandEventHooks(ConsoleCommandEvent $event)

Call the command event hooks.

static 
getSubscribedEvents()

No description

Details

__construct()

No description

getAllHooks()

No description

add(callable $callback, string $hook, string $name = '*')

Add a hook

Parameters

callable $callback

The callback function to call

string $hook

The name of the hook to add

string $name

The name of the command to hook ('*' for all)

recordHookOptions($commandInfo, $name)

No description

Parameters

$commandInfo
$name

static getNames($command, $callback)

No description

Parameters

$command
$callback

static protected getNamesUsingCommands($command)

No description

Parameters

$command

static protected getClassNameFromCallback($callback)

If a command hook does not specify any particular command name that it should be attached to, then it will be applied to every command that is defined in the same class as the hook.

This is controlled by using the namespace + class name of the implementing class of the callback hook.

Parameters

$callback

addReplaceCommandHook(ReplaceCommandHookInterface $replaceCommandHook, $name)

Add a replace command hook

Parameters

ReplaceCommandHookInterface $replaceCommandHook
$name

addPreCommandEventDispatcher(EventDispatcherInterface $eventDispatcher, $name = '*')

No description

Parameters

EventDispatcherInterface $eventDispatcher
$name

addCommandEventDispatcher(EventDispatcherInterface $eventDispatcher, $name = '*')

No description

Parameters

EventDispatcherInterface $eventDispatcher
$name

addPostCommandEventDispatcher(EventDispatcherInterface $eventDispatcher, $name = '*')

No description

Parameters

EventDispatcherInterface $eventDispatcher
$name

addCommandEvent(EventSubscriberInterface $eventSubscriber)

No description

Parameters

EventSubscriberInterface $eventSubscriber

addInitializeHook(InitializeHookInterface $initializeHook, type $name = '*')

Add an configuration provider hook

Parameters

InitializeHookInterface $initializeHook
type $name

The name of the command to hook ('*' for all)

addOptionHook(OptionHookInterface $interactor, type $name = '*')

Add an option hook

Parameters

OptionHookInterface $interactor
type $name

The name of the command to hook ('*' for all)

addInteractor(InteractorInterface $interactor, type $name = '*')

Add an interact hook

Parameters

InteractorInterface $interactor
type $name

The name of the command to hook ('*' for all)

addPreValidator(ValidatorInterface $validator, type $name = '*')

Add a pre-validator hook

Parameters

ValidatorInterface $validator
type $name

The name of the command to hook ('*' for all)

addValidator(ValidatorInterface $validator, type $name = '*')

Add a validator hook

Parameters

ValidatorInterface $validator
type $name

The name of the command to hook ('*' for all)

addPreCommandHook(ValidatorInterface $preCommand, type $name = '*')

Add a pre-command hook. This is the same as a validator hook, except that it will run after all of the post-validator hooks.

Parameters

ValidatorInterface $preCommand
type $name

The name of the command to hook ('*' for all)

addPostCommandHook(ProcessResultInterface $postCommand, type $name = '*')

Add a post-command hook. This is the same as a pre-process hook, except that it will run before the first pre-process hook.

Parameters

ProcessResultInterface $postCommand
type $name

The name of the command to hook ('*' for all)

addResultProcessor(ProcessResultInterface $resultProcessor, type $name = '*')

Add a result processor.

Parameters

ProcessResultInterface $resultProcessor
type $name

The name of the command to hook ('*' for all)

addAlterResult(AlterResultInterface $resultAlterer, type $name = '*')

Add a result alterer. After a result is processed by a result processor, an alter hook may be used to convert the result from one form to another.

Parameters

AlterResultInterface $resultAlterer
type $name

The name of the command to hook ('*' for all)

addStatusDeterminer(StatusDeterminerInterface $statusDeterminer, type $name = '*')

Add a status determiner. Usually, a command should return an integer on error, or a result object on success (which implies a status code of zero). If a result contains the status code in some other field, then a status determiner can be used to call the appropriate accessor method to determine the status code. This is usually not necessary, though; a command that fails may return a CommandError object, which contains a status code and a result message to display.

Parameters

StatusDeterminerInterface $statusDeterminer
type $name

The name of the command to hook ('*' for all)

See also

CommandError::getExitCode

addOutputExtractor(ExtractOutputInterface $outputExtractor, type $name = '*')

Add an output extractor. If a command returns an object object, by default it is passed directly to the output formatter (if in use) for rendering. If the result object contains more information than just the data to render, though, then an output extractor can be used to call the appopriate accessor method of the result object to get the data to rendered. This is usually not necessary, though; it is preferable to have complex result objects implement the OutputDataInterface.

Parameters

ExtractOutputInterface $outputExtractor
type $name

The name of the command to hook ('*' for all)

See also

OutputDataInterface::getOutputData

getHookOptionsForCommand($command)

No description

Parameters

$command

CommandInfo[] getHookOptions($names)

No description

Parameters

$names

Return Value

CommandInfo[]

callable[] getHooks(string|array $names, string[] $hooks, $annotationData = null)

Get a set of hooks with the provided name(s). Include the pre- and post- hooks, and also include the global hooks ('*') in addition to the named hooks provided.

Parameters

string|array $names

The name of the function being hooked.

string[] $hooks

A list of hooks (e.g. [HookManager::ALTER_RESULT])

$annotationData

Return Value

callable[]

protected addWildcardHooksToNames($names, $annotationData = null)

No description

Parameters

$names
$annotationData

callable[] get(string|array $names, string[] $hooks)

Get a set of hooks with the provided name(s).

Parameters

string|array $names

The name of the function being hooked.

string[] $hooks

The list of hook names (e.g. [HookManager::ALTER_RESULT])

Return Value

callable[]

callable[] getHook(string $name, string $hook)

Get a single named hook.

Parameters

string $name

The name of the hooked method

string $hook

The specific hook name (e.g. alter)

Return Value

callable[]

callCommandEventHooks(ConsoleCommandEvent $event)

Call the command event hooks.

TODO: This should be moved to CommandEventHookDispatcher, which should become the class that implements EventSubscriberInterface. This change would break all clients, though, so postpone until next major release.

Parameters

ConsoleCommandEvent $event

static getSubscribedEvents()

No description