class EventDispatcher (View source)

The Event Dispatcher.

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

Properties

protected $composer
protected $io
protected $loader
protected $process
protected $listeners

Methods

__construct(Composer $composer, IOInterface $io, ProcessExecutor $process = null)

Constructor.

int
dispatch(string $eventName, Event $event = null)

Dispatch an event

int
dispatchScript(string $eventName, bool $devMode = false, array $additionalArgs = array(), array $flags = array())

Dispatch a script event.

int
dispatchPackageEvent(string $eventName, bool $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)

Dispatch a package event.

int
dispatchInstallerEvent(string $eventName, bool $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())

Dispatch a installer event.

int
doDispatch(Event $event)

Triggers the listeners of an event.

getPhpExecCommand()

No description

executeEventPhpScript(string $className, string $methodName, Event $event)

No description

checkListenerExpectedEvent(mixed $target, Event $event)

No description

addListener(string $eventName, callable $listener, int $priority = 0)

Add a listener for a particular event

addSubscriber(EventSubscriberInterface $subscriber)

Adds object methods as listeners for the events in getSubscribedEvents

array
getListeners(Event $event)

Retrieves all listeners for a given event

bool
hasEventListeners(Event $event)

Checks if an event has listeners registered

array
getScriptListeners(Event $event)

Finds all listeners defined as scripts in the package

bool
isPhpScript(string $callable)

Checks if string given references a class path and method

bool
isComposerScript(string $callable)

Checks if string given references a composer run-script

number
pushEvent(Event $event)

Push an event to the stack of active event

mixed
popEvent()

Pops the active event from the stack

Details

__construct(Composer $composer, IOInterface $io, ProcessExecutor $process = null)

Constructor.

Parameters

Composer $composer The composer instance
IOInterface $io The IOInterface instance
ProcessExecutor $process

int dispatch(string $eventName, Event $event = null)

Dispatch an event

Parameters

string $eventName An event name
Event $event

Return Value

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

int dispatchScript(string $eventName, bool $devMode = false, array $additionalArgs = array(), array $flags = array())

Dispatch a script event.

Parameters

string $eventName The constant in ScriptEvents
bool $devMode
array $additionalArgs Arguments passed by the user
array $flags Optional flags to pass data not as argument

Return Value

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

int dispatchPackageEvent(string $eventName, bool $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)

Dispatch a package event.

Parameters

string $eventName The constant in PackageEvents
bool $devMode Whether or not we are in dev mode
PolicyInterface $policy The policy
Pool $pool The pool
CompositeRepository $installedRepo The installed repository
Request $request The request
array $operations The list of operations
OperationInterface $operation The package being installed/updated/removed

Return Value

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

int dispatchInstallerEvent(string $eventName, bool $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())

Dispatch a installer event.

Parameters

string $eventName The constant in InstallerEvents
bool $devMode Whether or not we are in dev mode
PolicyInterface $policy The policy
Pool $pool The pool
CompositeRepository $installedRepo The installed repository
Request $request The request
array $operations The list of operations

Return Value

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

protected int doDispatch(Event $event)

Triggers the listeners of an event.

Parameters

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

Return Value

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

Exceptions

Exception

protected getPhpExecCommand()

protected executeEventPhpScript(string $className, string $methodName, Event $event)

Parameters

string $className
string $methodName
Event $event Event invoking the PHP callable

protected Event checkListenerExpectedEvent(mixed $target, Event $event)

Parameters

mixed $target
Event $event

Return Value

Event

addListener(string $eventName, callable $listener, int $priority = 0)

Add a listener for a particular event

Parameters

string $eventName The event name - typically a constant
callable $listener A callable expecting an event argument
int $priority A higher value represents a higher priority

addSubscriber(EventSubscriberInterface $subscriber)

Adds object methods as listeners for the events in getSubscribedEvents

Parameters

EventSubscriberInterface $subscriber

See also

EventSubscriberInterface

protected array getListeners(Event $event)

Retrieves all listeners for a given event

Parameters

Event $event

Return Value

array All listeners: callables and scripts

bool hasEventListeners(Event $event)

Checks if an event has listeners registered

Parameters

Event $event

Return Value

bool

protected array getScriptListeners(Event $event)

Finds all listeners defined as scripts in the package

Parameters

Event $event Event object

Return Value

array Listeners

protected bool isPhpScript(string $callable)

Checks if string given references a class path and method

Parameters

string $callable

Return Value

bool

protected bool isComposerScript(string $callable)

Checks if string given references a composer run-script

Parameters

string $callable

Return Value

bool

protected number pushEvent(Event $event)

Push an event to the stack of active event

Parameters

Event $event

Return Value

number

Exceptions

RuntimeException

protected mixed popEvent()

Pops the active event from the stack

Return Value

mixed