Documentation

EventDispatcher
in package

The Event Dispatcher.

Example in command: $dispatcher = new EventDispatcher($this->getComposer(), $this->getApplication()->getIO()); // ... $dispatcher->dispatch(ScriptEvents::POST_INSTALL_CMD); // ...

Tags
author

François Pluchino francois.pluchino@opendisplay.com

author

Jordi Boggiano j.boggiano@seld.be

author

Nils Adermann naderman@naderman.de

Table of Contents

$composer  : mixed
$io  : mixed
$listeners  : mixed
$loader  : mixed
$process  : mixed
$eventStack  : mixed
__construct()  : mixed
Constructor.
addListener()  : mixed
Add a listener for a particular event
addSubscriber()  : mixed
Adds object methods as listeners for the events in getSubscribedEvents
dispatch()  : int
Dispatch an event
dispatchInstallerEvent()  : int
Dispatch a installer event.
dispatchPackageEvent()  : int
Dispatch a package event.
dispatchScript()  : int
Dispatch a script event.
hasEventListeners()  : bool
Checks if an event has listeners registered
checkListenerExpectedEvent()  : Event
doDispatch()  : int
Triggers the listeners of an event.
executeEventPhpScript()  : mixed
getListeners()  : array<string|int, mixed>
Retrieves all listeners for a given event
getPhpExecCommand()  : mixed
getScriptListeners()  : array<string|int, mixed>
Finds all listeners defined as scripts in the package
isComposerScript()  : bool
Checks if string given references a composer run-script
isPhpScript()  : bool
Checks if string given references a class path and method
popEvent()  : mixed
Pops the active event from the stack
pushEvent()  : number
Push an event to the stack of active event
ensureBinDirIsInPath()  : mixed
serializeCallback()  : mixed

Properties

Methods

addListener()

Add a listener for a particular event

public addListener(string $eventName, callable $listener, int $priority) : mixed
Parameters
$eventName : string

The event name - typically a constant

$listener : callable

A callable expecting an event argument

$priority : int

A higher value represents a higher priority

Return values
mixed

dispatch()

Dispatch an event

public dispatch(string $eventName[, Event $event = null ]) : int
Parameters
$eventName : string

An event name

$event : Event = null
Return values
int

return code of the executed script if any, for php scripts a false return value is changed to 1, anything else to 0

dispatchInstallerEvent()

Dispatch a installer event.

public dispatchInstallerEvent(string $eventName, bool $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request[, array<string|int, mixed> $operations = array() ]) : int
Parameters
$eventName : string

The constant in InstallerEvents

$devMode : bool

Whether or not we are in dev mode

$policy : PolicyInterface

The policy

$pool : Pool

The pool

$installedRepo : CompositeRepository

The installed repository

$request : Request

The request

$operations : array<string|int, mixed> = array()

The list of operations

Return values
int

return code of the executed script if any, for php scripts a false return value is changed to 1, anything else to 0

dispatchPackageEvent()

Dispatch a package event.

public dispatchPackageEvent(string $eventName, bool $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array<string|int, mixed> $operations, OperationInterface $operation) : int
Parameters
$eventName : string

The constant in PackageEvents

$devMode : bool

Whether or not we are in dev mode

$policy : PolicyInterface

The policy

$pool : Pool

The pool

$installedRepo : CompositeRepository

The installed repository

$request : Request

The request

$operations : array<string|int, mixed>

The list of operations

$operation : OperationInterface

The package being installed/updated/removed

Return values
int

return code of the executed script if any, for php scripts a false return value is changed to 1, anything else to 0

dispatchScript()

Dispatch a script event.

public dispatchScript(string $eventName[, bool $devMode = false ][, array<string|int, mixed> $additionalArgs = array() ][, array<string|int, mixed> $flags = array() ]) : int
Parameters
$eventName : string

The constant in ScriptEvents

$devMode : bool = false
$additionalArgs : array<string|int, mixed> = array()

Arguments passed by the user

$flags : array<string|int, mixed> = array()

Optional flags to pass data not as argument

Return values
int

return code of the executed script if any, for php scripts a false return value is changed to 1, anything else to 0

hasEventListeners()

Checks if an event has listeners registered

public hasEventListeners(Event $event) : bool
Parameters
$event : Event
Return values
bool

checkListenerExpectedEvent()

protected checkListenerExpectedEvent(mixed $target, Event $event) : Event
Parameters
$target : mixed
$event : Event
Return values
Event

doDispatch()

Triggers the listeners of an event.

protected doDispatch(Event $event) : int
Parameters
$event : Event

The event object to pass to the event handlers/listeners.

Tags
throws
RuntimeException|Exception
Return values
int

return code of the executed script if any, for php scripts a false return value is changed to 1, anything else to 0

executeEventPhpScript()

protected executeEventPhpScript(string $className, string $methodName, Event $event) : mixed
Parameters
$className : string
$methodName : string
$event : Event

Event invoking the PHP callable

Return values
mixed

getListeners()

Retrieves all listeners for a given event

protected getListeners(Event $event) : array<string|int, mixed>
Parameters
$event : Event
Return values
array<string|int, mixed>

All listeners: callables and scripts

getPhpExecCommand()

protected getPhpExecCommand() : mixed
Return values
mixed

getScriptListeners()

Finds all listeners defined as scripts in the package

protected getScriptListeners(Event $event) : array<string|int, mixed>
Parameters
$event : Event

Event object

Return values
array<string|int, mixed>

Listeners

isComposerScript()

Checks if string given references a composer run-script

protected isComposerScript(string $callable) : bool
Parameters
$callable : string
Return values
bool

isPhpScript()

Checks if string given references a class path and method

protected isPhpScript(string $callable) : bool
Parameters
$callable : string
Return values
bool

popEvent()

Pops the active event from the stack

protected popEvent() : mixed
Return values
mixed

pushEvent()

Push an event to the stack of active event

protected pushEvent(Event $event) : number
Parameters
$event : Event
Tags
throws
RuntimeException
Return values
number

ensureBinDirIsInPath()

private ensureBinDirIsInPath() : mixed
Return values
mixed

serializeCallback()

private serializeCallback(mixed $cb) : mixed
Parameters
$cb : mixed
Return values
mixed

Search results