PVStaticPatterns

PVPatterns is the parent class for implementing Adapters, Observers, Intercepting Filters and Singletons on static methods.

Prodgiyview comes with 4 design patterns that can be extended to any object: Adapters, Observers, Intercepting Filters and Singletons. By extending this class to any object that uses static methods, they will have the capability of using these design patterns.

package

data

Methods

Apply a fitler if filter is set.

_applyFilter(string $class, string $method, mixed $data, array $options = array()) : mixed
static
access

protected

Arguments

$class

string

The name of the class the filter is in

$method

string

The method the filter is in

$data

mixed

The data that is being passed to the filter

$options

array

options to be passed to the filter. Passed options we be passed to the function. -'default_return' mixed: If no filter is return, the data passed in by default will be return. Can be overriden -'event' string: An event to associate with the filter. Default is null

Response

mixed

$data The data the function returns

Calls an adapter for this class. The easiest way of implementing an adapter is by placing the adapter at the top of the function that it is being called in. An infinite amout of parameters can be passed to the adapter BUT the parameters should be the same as the parents.

_callAdapter(string $class, string $method) : mixed
static
access

protected

Arguments

$class

string

The name of the class the adapter is in

$method

string

THe name of the method the class is being called from.

Response

mixed

$value A value that the adapter returns

Checks if an adapter is set for the function.

_hasAdapter( $class, string $method) : \boolea
static
access

protected

Arguments

$class

$method

string

The associated method

Response

\boolea

$hasAdapter Returns true if it has an adapter or false if it doesn not

Checks if a filter has been set.

_hasFilter(string $class, string $method) 
static

Arguments

$class

string

The class the filter is in

$method

string

The method of the class that the filter is in

Calls a methods that is an instance of an class. This method is generally faster than using user_call_func_array.

_invokeMethod(string $class, string $method, array $args) : mixed
static
access

protected

Arguments

$class

string

The name of the class to be called

$method

string

The name of the method in the class to be called

$args

array

An array of arguements. Arguements have to be embedded in an array to be called.

Response

mixed

$data Data returned by the function called

Calls a methods that is a static method of a class. This method is generally faster than using user_call_func_array.

_invokeStaticMethod(string $class, string $method, array $args) : mixed
static
access

protected

Arguments

$class

string

The name of the class to be called

$method

string

The name of the method in the class to be called

$args

array

An array of arguements. Arguements have to be embedded in an array to be called.

Response

mixed

$data Data returned by the function called

Write out the contents of adapters used to a log

_logAdapter(array $data) : void
static
access

private

Arguments

$data

array

The data in the adapter

Write out the contents of a filter used to a log

_logFilter(array $data) : void
static
access

private

Arguments

$data

array

The data in the filter

Write out the contents of an observer to a log.

_logObserver(array $data) : void
static
access

private

Arguments

$data

array

The data in the observer

Calls any functions that have been added to the observer if the event is present in the observers array.

_notify(string $event) : void
static
access

protected

Arguments

$event

string

The name of the even that occured that will trigger notifies

Breaks down the data to be logged from an adapter, filter or observer.

_prepareLogData(array $data) : string
static
access

private

Arguments

$data

array

Response

string

$message JSON encode message of information about the data

Adapters allows a method to be completely overwritten by calling a different class with the same method name. Adapters can also be used with closures. The adapter uses a strategy/adapter design pattern.

addAdapter(string $trigger_class, string $trigger_method, string $call_class, array $options = array()) : void
static
access

public

todo

add ability to adapt singleton class

Arguments

$trigger_class

string

The class that contains the function the adapter will respond too

$trigger_method

string

The method called that will have the adapter to be called.

$call_class

string

The new class to be called that has the same method name

$options

array

An array of options that be called -'object' string : Assumes that default method in the class to be called is static. If called object needs to be instantiated, change to object to 'instance' and one will be created before the adapter calls the function -'call_method' string: By default the method to be called to override the current one should be the same name. But this can be ovveridden to call a different method. -'type' string: The type of method being called. Default is class_method but if the method is a closure, set the type to be 'closure' and make the $trigger_method the closure

Will add an adapter for every method in the trigger_class to another class. The method will only be adapted to another class if the method in the trigger class has an adapter. This functionality can be very similiar to DI.

addClassAdapter(mixed $trigger_class, string $call_class, array $options = array()) : void
static
access

public

todo

Add ability to use singleton classes

Arguments

$trigger_class

mixed

This can either be the name of the class or an object whose methods will be adapted to another class. The class should be included or be autoloaded by this point.

$call_class

string

The call class is the classes methods that will be called in place of the methods in the trigger_class. These class does not have to be included as this point.

$options

array

Options that be used to further distinguish the behavior of the adapters added -'object' string: Determines if the object being adapted to is static or an instance.Default is static -'call_class' string: The name of the class that the methods will be adapted too. -'class' string: The name of the whose methods will be adapted to another class

Adds a filter to the class. Filters are for modifying a value within a class and should not interpet the normal flow within the method.

addFilter(string $class, string $method, string $filter_class, string $filter_method, array $options = array()) : void
static
access

public

Arguments

$class

string

The name of the class the filter is going in

$method

string

The name of the method the filter is in

$filter_class

string

The class that the filter resides in.

$filter_method

string

The method in the class that the parameters will be passed too.

$options

array

Options that can be set for further modifying the filter. -'object' string: If the method being called is static, static should be inserted. If its in an instance, 'instance' should be set. Default is set to static. -'event' string: Associate this filter with an event. -'type' string: The type of function being called. Default is class_method but if the function is a closure, set the type to be 'closure' and make the $filter_method the closure

Adds an observer to the class. Observer events can fired in any method to trigger a response.

addObserver(string $event, string $class, string $method, array $options = array()) : void
static
access

public

Arguments

$event

string

The name of the event that will cause a certain class and method to fire

$class

string

The name of the class that contains the function that will be fired for this event

$method

string

The name of the method that will be fired when the event occurs

$options

array

Options to further the define the firing of an event -'object' string : If the method being called is static, should be set to static. Else set to instance -'class' stinrg : The name of the class to be called. Default is the class that is passed in. -'method' string: The name of the method to be called. Default is the method that is passed in. -'type' string: The type of function being called. Default is class_method but if the function is a closure, set the type to be 'closure' and make the $method the closure

Remove all the filters from a class.

clearFilters(string $class, string $method) : void
static
access

public

Arguments

$class

string

The class the filter is in

$method

string

The method of the class that the filter is in

Removes all the observers assoicated with an event.

clearObservers(string $event) : void
static
access

public

Arguments

$event

string

The event to remove all the observers from

Returns the instance of a class. Used for implementing the singleton design pattern. Class will only be instantiated once.

getInstance() : object
static
access

public

Response

object

$instance Returns the instance of a class.

Removes an adapter.

removeAdapter( $class, string $method) : void
static
access

public

Arguments

$class

$method

string

The associated method

Removes an adapter for an entire class.

removeClassAdapter( $class) : void
static
access

public

Arguments

$class

Turn on/off the ability to trace an adapter.Turning on will log an adapter using PVLog when adapter is executed.

setAdapterTrace(boolean $trace = false) : void
static
access

public

Arguments

$trace

boolean

Default is false. If set to true, will trace adatper.

Turn on/off the ability to trace an filter.Turning on will log a filter using PVLog when filter is executed.

setFilterTrace(boolean $trace = false) : void
static
access

public

Arguments

$trace

boolean

Default is false. If set to true, will trace filter.

Turn on/off the ability to trace an observer.Turning on will log an observer using PVLog when the observer is executed.

setObserverTrace(boolean $trace = false) : void
static
access

public

Arguments

$trace

boolean

Default is false. If set to true, will trace observer.

Properties

The adapters that have been added

_adapters : 
static

Type(s)

Observers that have been added

_observers : 
static

Type(s)

Instances for singleton that have added

_instances : 
static

Type(s)

Intercepting filters that have been added

_filters : 
static

Type(s)

Boolean for following and logging adapters that have been added

_traceAdapters : 
static

Type(s)

Boolean for following and logging filters that have been added

_traceFilters : 
static

Type(s)

Boolean for following and logging observers that have been added.

_traceObservers : 
static

Type(s)