Composer API
Class

Composer\EventDispatcher\EventDispatcher

class EventDispatcher

The Event Dispatcher.

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

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.

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

Add a listener for a particular event

addSubscriber(EventSubscriberInterface $subscriber)

Adds object methods as listeners for the events in getSubscribedEvents

bool hasEventListeners(Event $event)

Checks if an event has listeners registered

Details

at line 59
public __construct(Composer $composer, IOInterface $io, ProcessExecutor $process = null)

Constructor.

Parameters

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

at line 75
public 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

at line 94
public 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

at line 114
public 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

at line 133
public 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

at line 364
public addListener(string $eventName, callable $listener, int $priority)

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

at line 376
public addSubscriber(EventSubscriberInterface $subscriber)

Adds object methods as listeners for the events in getSubscribedEvents

Parameters

EventSubscriberInterface $subscriber

See also

EventSubscriberInterface

at line 418
public bool hasEventListeners(Event $event)

Checks if an event has listeners registered

Parameters

Event $event

Return Value

bool