\Phabstractic\EventAggregator

The Aggregator Class

This class puts a whole bunch of publishers under one roof.

They each vie to change the state (causing an event to fire) of the aggregate with their own states, but they are filtered by a built in filter (usually a custom filter)

CHANGELOG

1.0 Created Aggregator - August 16th, 2013 2.0 Integrated into Primus 2 Changed Filter to FilterInterface - October 14th, 2015 3.0: updated to use observertrait and publishertrait reformatted for inclusion in phabstractic - July 31st, 2016

Summary

Methods
Properties
Constants
attachObserver()
detachObserver()
unlinkFromObservers()
getObservers()
setStateObject()
getStateObject()
announce()
__debugInfo()
detachPublisher()
attachPublisher()
unlinkFromPublishers()
getPublishers()
notifyObserver()
__construct()
getFilter()
setFilter()
No public properties found
No constants found
constructPublisherObservers()
constructObservedSubjects()
$publisherObservers
$publisherState
$observedSubjects
$filter
N/A
No private methods found
No private properties found
N/A

Properties

$publisherObservers

$publisherObservers : \Phabstractic\Patterns\Phabstractic\Data\Types\RestrictedSet

The observers (restricted set) that are listening to this publisher

Type

\Phabstractic\Patterns\Phabstractic\Data\Types\RestrictedSet

$publisherState

$publisherState : mixed

The state of the publisher, can be any object in this basic implementation

Type

mixed

$observedSubjects

$observedSubjects : \Phabstractic\Patterns\Phabstractic\Patterns\Resource\PublisherInterface

The subjects that this observer is listening to

For an observer that listens to multiple publishers with some added functionality see Phabstractic\Event\Aggregator

Type

\Phabstractic\Patterns\Phabstractic\Patterns\Resource\PublisherInterface

$filter

$filter : \Phabstractic\Event\Phabstractic\Event\Resource\Filter

The filter that determines when the aggregators state is changed

Type

\Phabstractic\Event\Phabstractic\Event\Resource\Filter

Methods

attachObserver()

attachObserver(\Phabstractic\Patterns\Phabstractic\Patterns\Resource\ObserverInterface  $observer) 

Attach an observer object to this publisher

This places an observer into the restricted set, as well as establishes this publisher as the observers subject

Parameters

\Phabstractic\Patterns\Phabstractic\Patterns\Resource\ObserverInterface $observer

detachObserver()

detachObserver(\Phabstractic\Patterns\Phabstractic\Patterns\Resource\ObserverInterface  $observer) 

Detach a listener/observer from the publisher

Removes the observer from the restricted set

Parameters

\Phabstractic\Patterns\Phabstractic\Patterns\Resource\ObserverInterface $observer

unlinkFromObservers()

unlinkFromObservers() 

Unlink this publisher from all observers

getObservers()

getObservers() : array

Retrieve an ARRAY of the observing objects for this publisher

Returns

array

setStateObject()

setStateObject(\Phabstractic\Event\Phabstractic\Patterns\Resource\StateInterface  $state) : boolean

Set the state of the aggregator, causes announce

We run the state through the filter, if present, and if it makes it we change the state and announce it to all our listeners

Parameters

\Phabstractic\Event\Phabstractic\Patterns\Resource\StateInterface $state

The State Object

Returns

boolean —

True if event is handled

getStateObject()

getStateObject() : \Phabstractic\Patterns\Phabstractic\Pattern\Resource\StateInterface

Retrieve the state object, whatever it may contain

Returns

\Phabstractic\Patterns\Phabstractic\Pattern\Resource\StateInterface

announce()

announce() 

Notify all the observers in the set of the state change, or otherwise

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

detachPublisher()

detachPublisher(\Phabstractic\Patterns\Resource\PublisherInterface  $publisher) 

This detaches the observer from its subject

Reciprocal methods exist in the publisher

Parameters

\Phabstractic\Patterns\Resource\PublisherInterface $publisher

attachPublisher()

attachPublisher(\Phabstractic\Patterns\Resource\PublisherInterface  $publisher) 

Attach this observer to a new publisher

This also acts like a 'set' function, and null is an acceptable value to be passed

Parameters

\Phabstractic\Patterns\Resource\PublisherInterface $publisher

unlinkFromPublishers()

unlinkFromPublishers() 

Remove this observer from all publishers

getPublishers()

getPublishers() : array

Return array of publishers

Returns

array

notifyObserver()

notifyObserver(\Phabstractic\Event\Phabstractic\Patterns\Resource\PublisherInterface  $publisher, \Phabstractic\Event\Phabstractic\Patterns\Resource\StateInterface  $state) : boolean

Get notified of a state change from one of our publishers

It accepts any capable publisher, and any capable state change information.

This for example is used in the universal event system, where state is the most recent event

Parameters

\Phabstractic\Event\Phabstractic\Patterns\Resource\PublisherInterface $publisher
\Phabstractic\Event\Phabstractic\Patterns\Resource\StateInterface $state

Maybe new state, (abstract event)

Returns

boolean —

true if handled (is AbstractEvent)

__construct()

__construct(\Phabstractic\Event\Phabstractic\Event\Filter  $filter = null, array  $publishers = array()) 

The Aggregator Class Constructor

This class is an observer and a publisher We take in all our publishers in an array and create another careful set for our observers too. We can also specify the head filter here too. (Usually a custom filter for this class)

Parameters

\Phabstractic\Event\Phabstractic\Event\Filter $filter

The head filter

array $publishers

The publishers we're listening to and aggregating

getFilter()

getFilter() : \Phabstractic\Event\Phabstractic\Event\Filter

Get the head filter that determines when the state is truly changed

Returns

\Phabstractic\Event\Phabstractic\Event\Filter

setFilter()

setFilter(\Phabstractic\Event\Phabstractic\Event\Filter  $filter) 

Set the head filter that determines when the state is truly changed

Parameters

\Phabstractic\Event\Phabstractic\Event\Filter $filter

constructPublisherObservers()

constructPublisherObservers() 

Make sure $this->publisherObservers has been constructed

constructObservedSubjects()

constructObservedSubjects() 

Make sure $this->observedSubjects has been constructed