\Phabstractic\EventFilter

Event Filter Class - Defines basic event predicate

This object allows event handlers to filter what events they respond to. It sits in front of the event handler and when an event contains all the things (strictly) that the filter contains it is passed along to the handler

CHANGELOG

1.0 Created Event Filter - August 16th, 2013 2.0 Integrated with Primus 2 - October 13th, 2015 3.0: changed getTagsObject and getCategoriesObject to --Set reformatted for inclusion in phabstractic - July 29th, 2016

Summary

Methods
Properties
Constants
configure()
saveSettings()
getSettings()
processSettings()
__construct()
getIdentifier()
setData()
setDataReference()
__debugInfo()
getState()
setState()
setStateWithArray()
setStateWithEvent()
getCategories()
getCategoriesSet()
addCategory()
addCategories()
setCategories()
removeCategory()
isCategory()
getTags()
getTagsSet()
addTag()
addTags()
setTags()
removeTag()
isTag()
getTarget()
getTargetReference()
setTarget()
setTargetReference()
getData()
getDataReference()
getFunction()
getClass()
getNamespace()
stop()
proceed()
isStopped()
force()
subdue()
isUnstoppable()
setStateWithFilter()
build()
makeStrict()
loosenUp()
enableFunction()
disableFunction()
isEventApplicable()
isLooselyApplicable()
isStrictlyApplicable()
No public properties found
No constants found
setIdentifier()
getNewIdentity()
$conf
$identityCounter
$identityPrefix
$identifier
$tags
$categories
$target
$data
$class
$function
$namespace
$stop
$force
N/A
No private methods found
$test
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

$identityCounter

$identityCounter : mixed

The Global Identity Generator Marker

When the identity is polled, this marker is 'advanced'. It's static to the class, in that way it's unique for each one.

Type

mixed — The current identity

$identityPrefix

$identityPrefix : mixed

The Identity Marker Prefix

Specific to a given class, this is placed with/in front of the identity (context) This is a bit strange to understand why it's not static, but imagine a finer grain of control

Type

mixed — The class's context/marker prefix

$identifier

$identifier : mixed

The event identifier

This is implementation specific

Type

mixed

$tags

$tags : \Phabstractic\Event\Resource\Falcraft\Data\Types\Set

The tags associated with this event

Type

\Phabstractic\Event\Resource\Falcraft\Data\Types\Set

$categories

$categories : \Phabstractic\Event\Resource\Falcraft\Data\Types\Set

The categories associated with this event

Type

\Phabstractic\Event\Resource\Falcraft\Data\Types\Set

$target

$target : mixed

The publishing object of the event

This doesn't necessarily always equal the object that generated the event. Kooky.

Type

mixed

$data

$data : mixed

Any data associated with the event

Type

mixed

$class

$class : string

The class that generated the event

This should ALWAYS equal the classname (if we're in a class) that generated the event.

Type

string

$function

$function : string

The function that generated the event

This should ALWAYS equal the function name that generated the event.

Type

string

$namespace

$namespace : string

The namespace generating the event

This should ALWAYS reflect the namespace of the class or function that generated the event.

Type

string

$stop

$stop : boolean

Has the event stopped propagation?

This has to be checked by handlers themselves

Type

boolean

$force

$force : boolean

Is this event currently unstoppable?

This has to be checked by conduits and handlers themselves

Type

boolean

$test

$test : 

The custom function to call (optional)

Type

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

__construct()

__construct(object  $target = null, array  $options = array()) 

The Filter Class Constructor

This builds a filter class with no state

Pass in a strict option to make an event match EVERYTHING in the filter object, rather than just one thing.

Options: strict - Strict Applicability

Parameters

object $target

The target of the event

array $options

getIdentifier()

getIdentifier() : mixed

Retrieve the event identifier

Returns

mixed

setData()

setData(mixed  $data) 

Set the data associated with the event

This is implementation specific

Parameters

mixed $data

setDataReference()

setDataReference(mixed  $data) 

Set the data associated with the event as a reference

This is implementation specific

Parameters

mixed $data

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

getState()

getState() : array

This returns an array containing the object state

This converts the event state to an array, tags and categories are set up as sub-arrays, as well as the available object members

Returns

array

setState()

setState(  $state) 

State Interface Status Set

In an 'event' publisher/observer ecosystem, such as asherwunk/phabstractic/-/event:

Replaces the current state object's data. In order for the observer/publisher pattern to work it is recommended that the caller of this function notifies all observers of the host object.

Parameters

$state

setStateWithArray()

setStateWithArray(array  $state, boolean  $morph = true) 

This sets or morphs an event with new information

If morph is set, the event doesn't clear it's information, and instead overwrites whats already there.

$state must include identifier

Parameters

array $state
boolean $morph

Whether we should replace or overwrite the object state

setStateWithEvent()

setStateWithEvent(\Phabstractic\Event\Resource\EventInterface  $state, boolean  $morph = true) 

This sets or morphs an event with new information

If morph is set, the event doesn't clear it's information, and instead overwrites whats already there.

Parameters

\Phabstractic\Event\Resource\EventInterface $state
boolean $morph

Whether we should replace or overwrite the object state

getCategories()

getCategories() : array

Return the categories of the event

NOTE: This returns an array

Returns

array

getCategoriesSet()

getCategoriesSet() : \Phabstractic\Event\Resource\Phabstractic\Data\Types\Set

Return the categories of the event

NOTE: This returns a set object

Returns

\Phabstractic\Event\Resource\Phabstractic\Data\Types\Set

addCategory()

addCategory(  $category) 

Add a category to the event

Parameters

$category

addCategories()

addCategories(array  $categories) 

Add cateogires to the event

Parameters

array $categories

setCategories()

setCategories(array  $categories) 

Set a bunch of categories at once

Parameters

array $categories

removeCategory()

removeCategory(  $category) 

Remove a category from the event

Parameters

$category

isCategory()

isCategory(  $category) : boolean

Does this event have a particular category?

Parameters

$category

Returns

boolean

getTags()

getTags() : array

Get the tags associated with this event

NOTE: This returns an array

Returns

array

getTagsSet()

getTagsSet() : \Phabstractic\Event\Resource\Phabstractic\Data\Types\Set

Get the tags associated with this event

NOTE: This returns a Set

Returns

\Phabstractic\Event\Resource\Phabstractic\Data\Types\Set

addTag()

addTag(string  $tag) 

Associate a tag with this event

Parameters

string $tag

addTags()

addTags(array  $tags) 

Add multiple tags to the event

Parameters

array $tags

setTags()

setTags(array  $tags) 

Set a bunch of tags to be associated with this event

Parameters

array $tags

removeTag()

removeTag(string  $tag) 

Dissasociate a particular tag from this event

Parameters

string $tag

isTag()

isTag(string  $tag) : boolean

Is a tag associated with this particular event

Parameters

string $tag

Returns

boolean

getTarget()

getTarget() : object

Returns the generator of the event

Returns

object

getTargetReference()

getTargetReference() : object

Returns the generator of the event's reference

Returns

object

setTarget()

setTarget(  $target) 

Sets the generator of the event

NOTE: Use this function out of the construction of an event with caution

Parameters

$target

setTargetReference()

setTargetReference(  $target) 

Sets the generator of the event's reference

Parameters

$target

getData()

getData() : mixed

Retrieve the data associated with the event

Returns

mixed

getDataReference()

getDataReference() : mixed

Retrieve the data associated with the event as a reference

Returns

mixed

getFunction()

getFunction() : string

Retrieve the event originating function

Returns

string

getClass()

getClass() : string

Retrieve the event originating class

Returns

string

getNamespace()

getNamespace() : string

Retrieve the event originating namespace

Returns

string

stop()

stop() 

Stop propagation of the event

This member is checked by the filters

proceed()

proceed() 

Allow the event to continue propogating

isStopped()

isStopped() : boolean

Has the propogation of this event stopped?

Returns

boolean

force()

force() 

Make this event unstoppable

subdue()

subdue() 

Make this event stoppable

isUnstoppable()

isUnstoppable() : boolean

Is this event unstoppable?

Checked by filters

Returns

boolean

build()

build(object  $target, string  $function, string  $class, string  $namespace, mixed  $data, array  $tags = array(), array  $cats = array()) 

Initialize the filter with values

This mimics the constructor to initialize the filter with the passed arguments

Parameters

object $target
string $function
string $class
string $namespace
mixed $data
array $tags
array $cats

makeStrict()

makeStrict() 

Make this filter require all fields, not just one

NOTE: Zend\Config\Config is constructed in feature to be malleable.

loosenUp()

loosenUp() 

Loosen up the filter, so it only requires one field match

NOTE: Zend\Config\Config is constructed in feature to be malleable.

enableFunction()

enableFunction(  $function) 

Enable a custom filter

Pass in the calleable value here

Parameters

$function

Custom calleable value

disableFunction()

disableFunction() 

Disbale the custom filter

isEventApplicable()

isEventApplicable(\Phabstractic\Event\Resource\EventInterface  $event) : boolean

Figures what kind of testing we need

Parameters

\Phabstractic\Event\Resource\EventInterface $event

Returns

boolean

isLooselyApplicable()

isLooselyApplicable(\Phabstractic\Event\Resource\EventInterface  $event) : boolean

Takes an event and compares it against the filter

If it matches on one account, the event is propagated

If this object is 'strict' we call strictlyApplicable instead

Parameters

\Phabstractic\Event\Resource\EventInterface $event

Returns

boolean

isStrictlyApplicable()

isStrictlyApplicable(\Phabstractic\Event\Falcraft\Event\Resource\AbstractEvent  $event,   $includeIdentifier = false) : boolean

See if an event matches the filter exactly

If one thing doesn't match between the event and the filter then we return false, instead of only one thing matching

Parameters

\Phabstractic\Event\Falcraft\Event\Resource\AbstractEvent $event

The event to compare

$includeIdentifier

Returns

boolean

setIdentifier()

setIdentifier(  $identifier = '') 

Set an Identifier

For the generic class we just generate a unique id

Parameters

$identifier

The identifier to set

getNewIdentity()

getNewIdentity() : mixed

Poll for New Identity

Overridable in a using class so that anything could be used as an identity, but by default it's an integer attached to a prefix. As new identities are polled, the integer increases.

Returns

mixed —

The new identity