EventManager/EventManager.php

Show: inherited
Table of Contents

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.

Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_EventManager  

\Zend_EventManager_EventManager

Package: Zend\EventManager

Event manager: notification system

Use the EventManager when you want to create a per-instance notification system for your objects.

Implements
\Zend_EventManager_EventCollection
\Zend_EventManager_SharedEventCollectionAware
Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Properties

Propertyprotectedstring $eventClass = 'Zend_EventManager_Event'

<p>Class representing the event being emitted</p>
Default value'Zend_EventManager_Event'Details
Type
string
Propertyprotectedarray $events = array()

Subscribed events and their listeners

<p>Array of Zend_Stdlib_PriorityQueue objects</p>
Default valuearray()Details
Type
array
Propertyprotectedarray $identifiers = array()

Identifiers, used to pull static signals from StaticEventManager

Default valuearray()Details
Type
array
Propertyprotectedfalse|null|\Zend_EventManager_StaticEventCollection $sharedCollections = null

Static collections

Default valuenullDetails
Type
false | null | \Zend_EventManager_StaticEventCollection

Methods

methodpublic__construct(null | string | int | array | \Traversable $identifiers = null) : void

Constructor

Allows optionally specifying identifier(s) to use to pull signals from a StaticEventManager.

Parameters
Name Type Description
$identifiers null | string | int | array | \Traversable
methodpublicaddIdentifiers(string | int | array | \Traversable $identifiers) : \Zend_EventManager_EventManager

Add some identifier(s) (appends to any currently set identifiers)

Parameters
Name Type Description
$identifiers string | int | array | \Traversable
Returns
Type Description
\Zend_EventManager_EventManager
methodpublicattach(string | array | \Zend_EventManager_ListenerAggregate $event, callback | int $callback = null, int $priority = 1) : \Zend_Stdlib_CallbackHandler | mixed

Attach a listener to an event

The first argument is the event, and the next argument describes a callback that will respond to that event. A CallbackHandler instance describing the event listener combination will be returned.

The last argument indicates a priority at which the event should be executed. By default, this value is 1; however, you may set it for any integer value. Higher values have higher priority (i.e., execute first).

You can specify "*" for the event name. In such cases, the listener will be triggered for every event.

Parameters
Name Type Description
$event string | array | \Zend_EventManager_ListenerAggregate

An event or array of event names. If a ListenerAggregate, proxies to {@link attachAggregate()}.

$callback callback | int

If string $event provided, expects PHP callback; for a ListenerAggregate $event, this will be the priority

$priority int

If provided, the priority at which to register the callback

Returns
Type Description
\Zend_Stdlib_CallbackHandler | mixed CallbackHandler if attaching callback (to allow later unsubscribe); mixed if attaching aggregate
methodpublicattachAggregate(\Zend_EventManager_ListenerAggregate $aggregate, int $priority = 1) : mixed

Attach a listener aggregate

Listener aggregates accept an EventCollection instance, and call attach() one or more times, typically to attach to multiple events using local methods.

Parameters
Name Type Description
$aggregate \Zend_EventManager_ListenerAggregate
$priority int

If provided, a suggested priority for the aggregate to use

Returns
Type Description
mixed return value of {@link Zend_EventManager_ListenerAggregate::attach()}
methodpublicclearListeners(string $event) : void

Clear all listeners for a given event

Parameters
Name Type Description
$event string
methodpublicdetach(\Zend_Stdlib_CallbackHandler | \Zend_EventManager_ListenerAggregate $listener) : bool

Unsubscribe a listener from an event

Parameters
Name Type Description
$listener \Zend_Stdlib_CallbackHandler | \Zend_EventManager_ListenerAggregate
Returns
Type Description
bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
Throws
Exception Description
\Zend_EventManager_Exception_InvalidArgumentException if invalid listener provided
methodpublicdetachAggregate(\Zend_EventManager_ListenerAggregate $aggregate) : mixed

Detach a listener aggregate

Listener aggregates accept an EventCollection instance, and call detach() of all previously attached listeners.

Parameters
Name Type Description
$aggregate \Zend_EventManager_ListenerAggregate
Returns
Type Description
mixed return value of {@link Zend_EventManager_ListenerAggregate::detach()}
methodpublicgetEvents() : array

Retrieve all registered events

Returns
Type Description
array
methodpublicgetIdentifiers() : array

Get the identifier(s) for this Zend_EventManager_EventManager

Returns
Type Description
array
methodpublicgetListeners(string $event) : \Zend_Stdlib_PriorityQueue

Retrieve all listeners for a given event

Parameters
Name Type Description
$event string
Returns
Type Description
\Zend_Stdlib_PriorityQueue
methodpublicgetSharedCollections() : false | \Zend_EventManager_SharedEventCollection

Get static collections container

Returns
Type Description
false | \Zend_EventManager_SharedEventCollection
methodprotectedgetSharedListeners(string $event) : array

Get list of all listeners attached to the shared collection for identifiers registered by this instance

Parameters
Name Type Description
$event string
Returns
Type Description
array
methodprotectedinsertListeners(\Zend_Stdlib_PriorityQueue $masterListeners, \Zend_Stdlib_PriorityQueue $listeners) : void

Add listeners to the master queue of listeners

Used to inject shared listeners and wildcard listeners.

Parameters
Name Type Description
$masterListeners \Zend_Stdlib_PriorityQueue
$listeners \Zend_Stdlib_PriorityQueue
methodpublicprepareArgs(array $args) : \ArrayObject

Prepare arguments

Use this method if you want to be able to modify arguments from within a listener. It returns an ArrayObject of the arguments, which may then be passed to trigger() or triggerUntil().

Parameters
Name Type Description
$args array
Returns
Type Description
\ArrayObject
methodpublicsetEventClass(string $class) : \Zend_EventManager_EventManager

Set the event class to utilize

Parameters
Name Type Description
$class string
Returns
Type Description
\Zend_EventManager_EventManager
methodpublicsetIdentifiers(string | int | array | \Traversable $identifiers) : \Zend_EventManager_EventManager

Set the identifiers (overrides any currently set identifiers)

Parameters
Name Type Description
$identifiers string | int | array | \Traversable
Returns
Type Description
\Zend_EventManager_EventManager
methodpublicsetSharedCollections(\Zend_EventManager_StaticEventCollection $collections) : void

Set static collections container

Parameters
Name Type Description
$collections \Zend_EventManager_StaticEventCollection
methodpublictrigger(string $event, string | object $target = null, array | \ArrayAccess $argv = array(), null | callback $callback = null) : \Zend_EventManager_ResponseCollection

Trigger all listeners for a given event

Can emulate triggerUntil() if the last argument provided is a callback.

Parameters
Name Type Description
$event string
$target string | object

Object calling emit, or symbol describing target (such as static method name)

$argv array | \ArrayAccess

Array of arguments; typically, should be associative

$callback null | callback
Returns
Type Description
\Zend_EventManager_ResponseCollection All listener return values
methodprotectedtriggerListeners(string $event, \EventDescription $e, null | callback $callback = null) : \ResponseCollection

Trigger listeners

Actual functionality for triggering listeners, to which both trigger() and triggerUntil() delegate.

Parameters
Name Type Description
$event string

Event name

$e \EventDescription
$callback null | callback
Returns
Type Description
\ResponseCollection
methodpublictriggerUntil(string $event, string | object $target, array | \ArrayAccess $argv = null, \Callable $callback = null) : \Zend_EventManager_ResponseCollection

Trigger listeners until return value of one causes a callback to evaluate to true

Triggers listeners until the provided callback evaluates the return value of one as true, or until all listeners have been executed.

Parameters
Name Type Description
$event string
$target string | object

Object calling emit, or symbol describing target (such as static method name)

$argv array | \ArrayAccess

Array of arguments; typically, should be associative

$callback \Callable
Returns
Type Description
\Zend_EventManager_ResponseCollection
Throws
Exception Description
\Zend_Stdlib_Exception_InvalidCallbackException if invalid callback provided
methodpublicunsetSharedCollections() : void

Remove any shared collections

Sets $sharedCollections to boolean false to disable ability to lazy-load static event manager instance.

Documentation was generated by phpDocumentor 2.0.0a8.