\Phabstractic\PatternsObserverTrait

Observer Class - The basic minimal observer functionality

Any object inheriting from Observer is prepared to perform a basic tricky function remapping handler. The observer object expects a string, and then converts that string into a method call as the handler of the state change

CHANGELOG

1.0 created Observer - August 16th, 2013 2.0 Adapted Observer to Primus - August 25th, 2015 3.0: changed to trait from class reformatted for inclusion in phabstractic - July 27th, 2016

Summary

Methods
Properties
Constants
detachPublisher()
attachPublisher()
unlinkFromPublishers()
getPublishers()
notifyObserver()
__debugInfo()
No public properties found
No constants found
constructObservedSubjects()
$observedSubjects
N/A
No private methods found
No private properties found
N/A

Properties

$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

Methods

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\Patterns\Resource\PublisherInterface  $publisher, \Phabstractic\Patterns\Resource\StateInterface  $state) : boolean

The meat of the observer.

This is where a state change gets transformed into an action

In this case the expected state change is a string, which gets turned into a method name and called (presumably defined in an extended class) [publishedFunction]

Parameters

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

Returns

boolean —

True if event is handled

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

constructObservedSubjects()

constructObservedSubjects() 

Make sure $this->observedSubjects has been constructed