\Phabstractic\EventConduit

The Conduit Class

This class uses observer to collect a bunch of events from multiple sources and then employs a map (filters as keys, handlerpriorityqueues as values) to send those events to each filter to fire each handler chain.

CHANGELOG

1.0: Created Conduit Class - August 16th, 2013 1.1: Enabled Aggregator Injection - October 7th, 2013 2.0: Integrated into Primus 2 Changed filter concrete to FilterInterface - October 14th, 2015 3.0: implements configurationinterface eliminated need for aggregator, just implements observer now reformatted for inclusion in phabstarctic - July 31st, 2016

Summary

Methods
Properties
Constants
configure()
saveSettings()
getSettings()
processSettings()
detachPublisher()
attachPublisher()
unlinkFromPublishers()
getPublishers()
notifyObserver()
__debugInfo()
__construct()
getFilters()
addFilter()
setFilter()
removeFilter()
getHandlerPriorityQueue()
getHandlerPriorityQueueReference()
No public properties found
No constants found
constructObservedSubjects()
$conf
$observedSubjects
N/A
No private methods found
$map
N/A

Properties

$conf

$conf : \Phabstractic\Features\Zend\Config\Config

The objects configuration object

Should be an instance of Zend/Config

Type

\Phabstractic\Features\Zend\Config\Config — The object configuration info

$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

$map

$map : \Phabstractic\Event\Falcraft\Data\Types\Map

The actual conduit map

Keys are filters, values are chains

Type

\Phabstractic\Event\Falcraft\Data\Types\Map

Methods

configure()

configure(array|string|\Phabstractic\Features\Zend\Config\Config  $configuration, string  $format = null, mixed  $context = null) : boolean

Configure An Object

Expects an array for configuration however, you can also pass it a filepath where it will read the information from a file automatically detecting the format using the file extension. You can also pass a Zend/Config object already made.

You can also pass a format specifier (forced format) for use in a if $configuration is a string formatted with such information. E.G. to load from a string in the format ini:

$this->configure($configString, 'ini');

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for reading formats by identifying an additional array in the property $this->configReaders. This will merge with the standard formats array.

Parameters

array|string|\Phabstractic\Features\Zend\Config\Config $configuration

The objects configuration information.

string $format

The forced format, or format for configuration string

mixed $context

Any additional information for a reader constructor, such as needed for the YAML format.

Returns

boolean —

True if instantiated

saveSettings()

saveSettings(string  $file, \Phabstractic\Features\Zend\Config\Writer\WriterInterface  $writer = null, boolean  $exclusive = true, mixed  $context = null) 

Save an Object's Configuration to a File

Takes an objects $conf property and writes the information contained therein to a file with a format automatically specified by the filename.

It is possible to retrieve a string of a particular format from this method by specifying the filename '#string' with an extension indicating the desired format, such as '#string.json'.

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for writing formats by identifying an additional array in the property $this->configWriters. This will merge with the standard formats array.

Parameters

string $file

The file path to write to, or '#string.ext'

\Phabstractic\Features\Zend\Config\Writer\WriterInterface $writer

The optional writer object supplied to use (such as a MySQL writer)

boolean $exclusive

Argument provided to toFile(), file exclusive lock when writing

mixed $context

Any additionla writer constructor information (YAML)

getSettings()

getSettings(string  $format,   $context = null) : string|boolean

Retrieve an Object's Configuration Information As String

This is a shortcut to ::saveSettings() which specifies a format and forces the return of a string, using the #string.ext filename -see documentation for ::saveSettings()-

Parameters

string $format

The format to return, must be supported by ::saveSettings(), use $this->configWriters to support additional formats.

$context

Returns

string|boolean —

The formatted string, or false otherwise

processSettings()

processSettings(\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface  $processor) 

Process an Object's Configuration

This uses a Zend\Config\Processor implementation to process the configuration information, such as constants. The processor must be supplied and implement ProcessorInterface

NOTE: Edits the $conf object in place.

Parameters

\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface $processor

The given processor object

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 aggregate will call this class when it fires.

When a state change occurs and the notify function is called, we first make sure it's an abstract event, otherwise we exit gracefully, and then we run it through the various filters and their event chains. Events are handled as references so they can be affected by the handlers they encounter (or filters, or conduits, etc)

Parameters

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

Returns

boolean —

true if handled (is AbstractEvent)

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

__construct()

__construct(array  $filters = array(), array  $options = array()) 

The Conduit Constructor

This takes an array of filters to set up the map

This can be a multidimensional array where 0 is the filter and 1 is the priority queue Or it can just be a filter object, in which case an empty priority queue is instantiated

Parameters

array $filters
array $options

getFilters()

getFilters() : array

Retrieve all the filters registered with the conduit as an array

Returns

array

setFilter()

setFilter(\Phabstractic\Event\Falcraft\Event\Resource\Filter  $filter, \Phabstractic\Event\Falcraft\Event\Resource\HandlerPriorityQueue  $queue) 

Associate a given filter, in the map, with a given priority queue

Parameters

\Phabstractic\Event\Falcraft\Event\Resource\Filter $filter

The filter to set

\Phabstractic\Event\Falcraft\Event\Resource\HandlerPriorityQueue $queue

The given queue to be used

removeFilter()

removeFilter(\Phabstractic\Event\Falcraft\Event\Resource\Filter  $filter) 

Remove a filter from the map, this also of course removes the queue it represents

Parameters

\Phabstractic\Event\Falcraft\Event\Resource\Filter $filter

The filter to remove

getHandlerPriorityQueue()

getHandlerPriorityQueue(\Phabstractic\Event\Phabstractic\Event\Filter  $filter) : \Phabstractic\Event\Phabstractic\Event\HandlerPriorityQueue

Retrieve HandlerPriorityQueue associated to given filter

Parameters

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

Returns

\Phabstractic\Event\Phabstractic\Event\HandlerPriorityQueue

getHandlerPriorityQueueReference()

getHandlerPriorityQueueReference(\Phabstractic\Event\Phabstractic\Event\Filter  $filter) : \Phabstractic\Event\Phabstractic\Event\HandlerPriorityQueue

Retrieve HandlerPriorityQueue associated to given filter as reference

Parameters

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

Returns

\Phabstractic\Event\Phabstractic\Event\HandlerPriorityQueue

constructObservedSubjects()

constructObservedSubjects() 

Make sure $this->observedSubjects has been constructed