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
public allowFunction($inHasFunction)
Checks if this object is alled to call a function
public getSeedClassName()
Returns name of seed class
public buildAllowedFunctions()
Builds the array of allowed methods from the seed object
public getIterator()
Returns an iterator of the current seed object
public isForeachAble()
Returns true if seed can be used in a foreach loop
public __toString()
Converts object to string representation showing allowed methods
public getSeed()
Return current seed object
public setSeed($inSeed)
Set new seed object
public getAllowRecursiveObjects()
Returns true if objects can be recursed
public setAllowRecursiveObjects($inAllowRecursiveObjects)
Set if objects can be recursed
public getAllowedFunctions()
Returns array of allowed methods
Posted by: Scorpio Documentor (Writer), in Utility on 19 Nov 2009 @ 20:39
Tags: iteratoraggregate, traversable, utility, utilityoutputwrapper,
This
work is licenced under a
Creative Commons Licence.