utilityOutputWrapper is used for pushing objects to a template layer. It prevents access to methods that could change the state of the object e.g. saving or setting new data, meaning that your template layer is "safe" to open up to external developers. The wrapping extends to sub-objects or arrays. This means that any methods that return new objects or arrays will themselves be wrapped by output wrapper.
Attempts to call barred methods results in an exception being thrown.
Wrapped objects have an __toString implementation that will display the permitted methods if the object is used as a string. This is useful for debugging when you are not sure what is available to be called, or if you just want to see the methods on the object.
Additional methods are added for certain objects. These pre-defined methods include:
An additional, un-documented, method is provided for cases where you really need the original object. getSeed will return the original object un-wrapped.
Note: if you use instanceof or is_a() you will get the output wrapper class back - not the original class.
// example $var = utilityOutputWrapper::wrap(new stdClass()); // wrap existing object with exceptions $wrapped = utilityOutputWrapper::wrap( $existingObject, array('allowThis', 'allowThat'), // allowed methods array('blockThis','blockThat') // blocked methods );
public __construct($inSeed, [$inAlwaysAllow = null], [$inAlwaysIgnore = null])
Returns new utilityOutputWrapper wrapping $inSeed.
Optionally for objects an array of methods can be specified that are always allowed, or that are always ignored. By default get*, is*, has* allow*, can* and count* methods are allowed.
public static wrap($inItem, [$inAlwaysAllow = null], [$inAlwaysIgnore = null])
Function will wrap the item only allowing allowed commands to be executed
public __call($function, $args)
Overloaded call to intercept object calls
Checks if this object is alled to call a function
Returns name of seed class
Builds the array of allowed methods from the seed object
Returns an iterator of the current seed object
Returns true if seed can be used in a foreach loop
Converts object to string representation showing allowed methods
Return current seed object
Set new seed object
Returns true if objects can be recursed
Set if objects can be recursed
Returns array of allowed methods