Merge pull request #4446 from spekulatius/codestyle

remove tailing spaces in view related classes
This commit is contained in:
Damian Mooyman 2015-07-30 14:42:09 +12:00
commit c170f90d5e
3 changed files with 101 additions and 101 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Interface that is implemented by any classes that want to expose a method that can be called in any * Interface that is implemented by any classes that want to expose a method that can be called in any
* scope in a template. * scope in a template.
* *
* Director::AbsoluteBaseURL is an example of this. * Director::AbsoluteBaseURL is an example of this.

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Interface that is implemented by any classes that want to expose a method that can be called in any * Interface that is implemented by any classes that want to expose a method that can be called in any
* scope in a template that returns values dependant on the state of the iterator of the current scope. * scope in a template that returns values dependant on the state of the iterator of the current scope.
* *
* SSViewer_BasicIteratorSupport is an example of this. See also @TemplateGlobalProvider * SSViewer_BasicIteratorSupport is an example of this. See also @TemplateGlobalProvider

View File

@ -10,7 +10,7 @@
* @subpackage view * @subpackage view
*/ */
class ViewableData extends Object implements IteratorAggregate { class ViewableData extends Object implements IteratorAggregate {
/** /**
* An array of objects to cast certain fields to. This is set up as an array in the format: * An array of objects to cast certain fields to. This is set up as an array in the format:
* *
@ -26,7 +26,7 @@ class ViewableData extends Object implements IteratorAggregate {
private static $casting = array( private static $casting = array(
'CSSClasses' => 'Varchar' 'CSSClasses' => 'Varchar'
); );
/** /**
* The default object to cast scalar fields to if casting information is not specified, and casting to an object * The default object to cast scalar fields to if casting information is not specified, and casting to an object
* is required. * is required.
@ -35,12 +35,12 @@ class ViewableData extends Object implements IteratorAggregate {
* @config * @config
*/ */
private static $default_cast = 'Text'; private static $default_cast = 'Text';
/** /**
* @var array * @var array
*/ */
private static $casting_cache = array(); private static $casting_cache = array();
// ----------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------
/** /**
@ -49,19 +49,19 @@ class ViewableData extends Object implements IteratorAggregate {
* @var ViewableData * @var ViewableData
*/ */
protected $failover; protected $failover;
/** /**
* @var ViewableData * @var ViewableData
*/ */
protected $customisedObject; protected $customisedObject;
/** /**
* @var array * @var array
*/ */
private $objCache = array(); private $objCache = array();
// ----------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------
/** /**
* Converts a field spec into an object creator. For example: "Int" becomes "new Int($fieldName);" and "Varchar(50)" * Converts a field spec into an object creator. For example: "Int" becomes "new Int($fieldName);" and "Varchar(50)"
* becomes "new Varchar($fieldName, 50);". * becomes "new Varchar($fieldName, 50);".
@ -72,7 +72,7 @@ class ViewableData extends Object implements IteratorAggregate {
public static function castingObjectCreator($fieldSchema) { public static function castingObjectCreator($fieldSchema) {
Deprecation::notice('2.5', 'Use Object::create_from_string() instead'); Deprecation::notice('2.5', 'Use Object::create_from_string() instead');
} }
/** /**
* Convert a field schema (e.g. "Varchar(50)") into a casting object creator array that contains both a className * Convert a field schema (e.g. "Varchar(50)") into a casting object creator array that contains both a className
* and castingHelper constructor code. See {@link castingObjectCreator} for more information about the constructor. * and castingHelper constructor code. See {@link castingObjectCreator} for more information about the constructor.
@ -83,9 +83,9 @@ class ViewableData extends Object implements IteratorAggregate {
public static function castingObjectCreatorPair($fieldSchema) { public static function castingObjectCreatorPair($fieldSchema) {
Deprecation::notice('2.5', 'Use Object::create_from_string() instead'); Deprecation::notice('2.5', 'Use Object::create_from_string() instead');
} }
// FIELD GETTERS & SETTERS ----------------------------------------------------------------------------------------- // FIELD GETTERS & SETTERS -----------------------------------------------------------------------------------------
/** /**
* Check if a field exists on this object or its failover. * Check if a field exists on this object or its failover.
* *
@ -95,7 +95,7 @@ class ViewableData extends Object implements IteratorAggregate {
public function __isset($property) { public function __isset($property) {
return $this->hasField($property) || ($this->failover && $this->failover->hasField($property)); return $this->hasField($property) || ($this->failover && $this->failover->hasField($property));
} }
/** /**
* Get the value of a property/field on this object. This will check if a method called get{$property} exists, then * Get the value of a property/field on this object. This will check if a method called get{$property} exists, then
* check if a field is available using {@link ViewableData::getField()}, then fall back on a failover object. * check if a field is available using {@link ViewableData::getField()}, then fall back on a failover object.
@ -112,7 +112,7 @@ class ViewableData extends Object implements IteratorAggregate {
return $this->failover->$property; return $this->failover->$property;
} }
} }
/** /**
* Set a property/field on this object. This will check for the existence of a method called set{$property}, then * Set a property/field on this object. This will check for the existence of a method called set{$property}, then
* use the {@link ViewableData::setField()} method. * use the {@link ViewableData::setField()} method.
@ -127,7 +127,7 @@ class ViewableData extends Object implements IteratorAggregate {
$this->setField($property, $value); $this->setField($property, $value);
} }
} }
/** /**
* Check if a field exists on this object. This should be overloaded in child classes. * Check if a field exists on this object. This should be overloaded in child classes.
* *
@ -137,7 +137,7 @@ class ViewableData extends Object implements IteratorAggregate {
public function hasField($field) { public function hasField($field) {
return property_exists($this, $field); return property_exists($this, $field);
} }
/** /**
* Get the value of a field on this object. This should be overloaded in child classes. * Get the value of a field on this object. This should be overloaded in child classes.
* *
@ -147,7 +147,7 @@ class ViewableData extends Object implements IteratorAggregate {
public function getField($field) { public function getField($field) {
return $this->$field; return $this->$field;
} }
/** /**
* Set a field on this object. This should be overloaded in child classes. * Set a field on this object. This should be overloaded in child classes.
* *
@ -157,9 +157,9 @@ class ViewableData extends Object implements IteratorAggregate {
public function setField($field, $value) { public function setField($field, $value) {
$this->$field = $value; $this->$field = $value;
} }
// ----------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------
/** /**
* Add methods from the {@link ViewableData::$failover} object, as well as wrapping any methods prefixed with an * Add methods from the {@link ViewableData::$failover} object, as well as wrapping any methods prefixed with an
* underscore into a {@link ViewableData::cachedCall()}. * underscore into a {@link ViewableData::cachedCall()}.
@ -168,12 +168,12 @@ class ViewableData extends Object implements IteratorAggregate {
if($this->failover) { if($this->failover) {
if(is_object($this->failover)) $this->addMethodsFrom('failover'); if(is_object($this->failover)) $this->addMethodsFrom('failover');
else user_error("ViewableData::\$failover set to a non-object", E_USER_WARNING); else user_error("ViewableData::\$failover set to a non-object", E_USER_WARNING);
if(isset($_REQUEST['debugfailover'])) { if(isset($_REQUEST['debugfailover'])) {
Debug::message("$this->class created with a failover class of {$this->failover->class}"); Debug::message("$this->class created with a failover class of {$this->failover->class}");
} }
} }
foreach($this->allMethodNames() as $method) { foreach($this->allMethodNames() as $method) {
if($method[0] == '_' && $method[1] != '_') { if($method[0] == '_' && $method[1] != '_') {
$this->createMethod( $this->createMethod(
@ -181,10 +181,10 @@ class ViewableData extends Object implements IteratorAggregate {
); );
} }
} }
parent::defineMethods(); parent::defineMethods();
} }
/** /**
* Merge some arbitrary data in with this object. This method returns a {@link ViewableData_Customised} instance * Merge some arbitrary data in with this object. This method returns a {@link ViewableData_Customised} instance
* with references to both this and the new custom data. * with references to both this and the new custom data.
@ -198,16 +198,16 @@ class ViewableData extends Object implements IteratorAggregate {
if(is_array($data) && (empty($data) || ArrayLib::is_associative($data))) { if(is_array($data) && (empty($data) || ArrayLib::is_associative($data))) {
$data = new ArrayData($data); $data = new ArrayData($data);
} }
if($data instanceof ViewableData) { if($data instanceof ViewableData) {
return new ViewableData_Customised($this, $data); return new ViewableData_Customised($this, $data);
} }
throw new InvalidArgumentException ( throw new InvalidArgumentException (
'ViewableData->customise(): $data must be an associative array or a ViewableData instance' 'ViewableData->customise(): $data must be an associative array or a ViewableData instance'
); );
} }
/** /**
* @return ViewableData * @return ViewableData
*/ */
@ -221,9 +221,9 @@ class ViewableData extends Object implements IteratorAggregate {
public function setCustomisedObj(ViewableData $object) { public function setCustomisedObj(ViewableData $object) {
$this->customisedObject = $object; $this->customisedObject = $object;
} }
// CASTING --------------------------------------------------------------------------------------------------------- // CASTING ---------------------------------------------------------------------------------------------------------
/** /**
* Get the class a field on this object would be casted to, as well as the casting helper for casting a field to * Get the class a field on this object would be casted to, as well as the casting helper for casting a field to
* an object (see {@link ViewableData::castingHelper()} for information on casting helpers). * an object (see {@link ViewableData::castingHelper()} for information on casting helpers).
@ -257,7 +257,7 @@ class ViewableData extends Object implements IteratorAggregate {
if($this->failover) return $this->failover->castingHelper($field); if($this->failover) return $this->failover->castingHelper($field);
} }
/** /**
* Get the class name a field on this object will be casted to * Get the class name a field on this object will be casted to
* *
@ -267,12 +267,12 @@ class ViewableData extends Object implements IteratorAggregate {
public function castingClass($field) { public function castingClass($field) {
$spec = $this->castingHelper($field); $spec = $this->castingHelper($field);
if(!$spec) return null; if(!$spec) return null;
$bPos = strpos($spec,'('); $bPos = strpos($spec,'(');
if($bPos === false) return $spec; if($bPos === false) return $spec;
else return substr($spec, 0, $bPos); else return substr($spec, 0, $bPos);
} }
/** /**
* Return the string-format type for the given field. * Return the string-format type for the given field.
* *
@ -293,29 +293,29 @@ class ViewableData extends Object implements IteratorAggregate {
public function buildCastingCache(&$cache) { public function buildCastingCache(&$cache) {
$ancestry = array_reverse(ClassInfo::ancestry($this->class)); $ancestry = array_reverse(ClassInfo::ancestry($this->class));
$merge = true; $merge = true;
foreach($ancestry as $class) { foreach($ancestry as $class) {
if(!isset(self::$casting_cache[$class]) && $merge) { if(!isset(self::$casting_cache[$class]) && $merge) {
$mergeFields = is_subclass_of($class, 'DataObject') ? array('db', 'casting') : array('casting'); $mergeFields = is_subclass_of($class, 'DataObject') ? array('db', 'casting') : array('casting');
if($mergeFields) foreach($mergeFields as $field) { if($mergeFields) foreach($mergeFields as $field) {
$casting = Config::inst()->get($class, $field, Config::UNINHERITED); $casting = Config::inst()->get($class, $field, Config::UNINHERITED);
if($casting) foreach($casting as $field => $cast) { if($casting) foreach($casting as $field => $cast) {
if(!isset($cache[$field])) $cache[$field] = self::castingObjectCreatorPair($cast); if(!isset($cache[$field])) $cache[$field] = self::castingObjectCreatorPair($cast);
} }
} }
if($class == 'ViewableData') $merge = false; if($class == 'ViewableData') $merge = false;
} elseif($merge) { } elseif($merge) {
$cache = ($cache) ? array_merge(self::$casting_cache[$class], $cache) : self::$casting_cache[$class]; $cache = ($cache) ? array_merge(self::$casting_cache[$class], $cache) : self::$casting_cache[$class];
} }
if($class == 'ViewableData') break; if($class == 'ViewableData') break;
} }
} }
// TEMPLATE ACCESS LAYER ------------------------------------------------------------------------------------------- // TEMPLATE ACCESS LAYER -------------------------------------------------------------------------------------------
/** /**
* Render this object into the template, and get the result as a string. You can pass one of the following as the * Render this object into the template, and get the result as a string. You can pass one of the following as the
* $template parameter: * $template parameter:
@ -331,16 +331,16 @@ class ViewableData extends Object implements IteratorAggregate {
if(!is_object($template)) { if(!is_object($template)) {
$template = new SSViewer($template); $template = new SSViewer($template);
} }
$data = ($this->customisedObject) ? $this->customisedObject : $this; $data = ($this->customisedObject) ? $this->customisedObject : $this;
if($customFields instanceof ViewableData) { if($customFields instanceof ViewableData) {
$data = $data->customise($customFields); $data = $data->customise($customFields);
} }
if($template instanceof SSViewer) { if($template instanceof SSViewer) {
return $template->process($data, is_array($customFields) ? $customFields : null); return $template->process($data, is_array($customFields) ? $customFields : null);
} }
throw new UnexpectedValueException ( throw new UnexpectedValueException (
"ViewableData::renderWith(): unexpected $template->class object, expected an SSViewer instance" "ViewableData::renderWith(): unexpected $template->class object, expected an SSViewer instance"
); );
@ -377,7 +377,7 @@ class ViewableData extends Object implements IteratorAggregate {
protected function objCacheSet($key, $value) { protected function objCacheSet($key, $value) {
$this->objCache[$key] = $value; $this->objCache[$key] = $value;
} }
/** /**
* Get the value of a field on this object, automatically inserting the value into any available casting objects * Get the value of a field on this object, automatically inserting the value into any available casting objects
* that have been specified. * that have been specified.
@ -397,37 +397,37 @@ class ViewableData extends Object implements IteratorAggregate {
// HACK: Don't call the deprecated FormField::Name() method // HACK: Don't call the deprecated FormField::Name() method
$methodIsAllowed = true; $methodIsAllowed = true;
if($this instanceof FormField && $fieldName == 'Name') $methodIsAllowed = false; if($this instanceof FormField && $fieldName == 'Name') $methodIsAllowed = false;
if($methodIsAllowed && $this->hasMethod($fieldName)) { if($methodIsAllowed && $this->hasMethod($fieldName)) {
$value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->$fieldName(); $value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->$fieldName();
} else { } else {
$value = $this->$fieldName; $value = $this->$fieldName;
} }
if(!is_object($value) && ($this->castingClass($fieldName) || $forceReturnedObject)) { if(!is_object($value) && ($this->castingClass($fieldName) || $forceReturnedObject)) {
if(!$castConstructor = $this->castingHelper($fieldName)) { if(!$castConstructor = $this->castingHelper($fieldName)) {
$castConstructor = $this->config()->default_cast; $castConstructor = $this->config()->default_cast;
} }
$valueObject = Object::create_from_string($castConstructor, $fieldName); $valueObject = Object::create_from_string($castConstructor, $fieldName);
$valueObject->setValue($value, $this); $valueObject->setValue($value, $this);
$value = $valueObject; $value = $valueObject;
} }
if($cache) $this->objCacheSet($cacheName, $value); if($cache) $this->objCacheSet($cacheName, $value);
} }
if(!is_object($value) && $forceReturnedObject) { if(!is_object($value) && $forceReturnedObject) {
$default = $this->config()->default_cast; $default = $this->config()->default_cast;
$castedValue = new $default($fieldName); $castedValue = new $default($fieldName);
$castedValue->setValue($value); $castedValue->setValue($value);
$value = $castedValue; $value = $castedValue;
} }
return $value; return $value;
} }
/** /**
* A simple wrapper around {@link ViewableData::obj()} that automatically caches the result so it can be used again * A simple wrapper around {@link ViewableData::obj()} that automatically caches the result so it can be used again
* without re-running the method. * without re-running the method.
@ -439,7 +439,7 @@ class ViewableData extends Object implements IteratorAggregate {
public function cachedCall($field, $arguments = null, $identifier = null) { public function cachedCall($field, $arguments = null, $identifier = null) {
return $this->obj($field, $arguments, false, true, $identifier); return $this->obj($field, $arguments, false, true, $identifier);
} }
/** /**
* Checks if a given method/field has a valid value. If the result is an object, this will return the result of the * Checks if a given method/field has a valid value. If the result is an object, this will return the result of the
* exists method, otherwise will check if the result is not just an empty paragraph tag. * exists method, otherwise will check if the result is not just an empty paragraph tag.
@ -451,7 +451,7 @@ class ViewableData extends Object implements IteratorAggregate {
*/ */
public function hasValue($field, $arguments = null, $cache = true) { public function hasValue($field, $arguments = null, $cache = true) {
$result = $cache ? $this->cachedCall($field, $arguments) : $this->obj($field, $arguments, false, false); $result = $cache ? $this->cachedCall($field, $arguments) : $this->obj($field, $arguments, false, false);
if(is_object($result) && $result instanceof Object) { if(is_object($result) && $result instanceof Object) {
return $result->exists(); return $result->exists();
} else { } else {
@ -459,14 +459,14 @@ class ViewableData extends Object implements IteratorAggregate {
return ($result && $result !== '<p></p>'); return ($result && $result !== '<p></p>');
} }
} }
/**#@+ /**#@+
* @param string $field * @param string $field
* @param array $arguments * @param array $arguments
* @param bool $cache * @param bool $cache
* @return string * @return string
*/ */
/** /**
* Get the string value of a field on this object that has been suitable escaped to be inserted directly into a * Get the string value of a field on this object that has been suitable escaped to be inserted directly into a
* template. * template.
@ -475,37 +475,37 @@ class ViewableData extends Object implements IteratorAggregate {
$result = $this->obj($field, $arguments, false, $cache); $result = $this->obj($field, $arguments, false, $cache);
return (is_object($result) && $result instanceof Object) ? $result->forTemplate() : $result; return (is_object($result) && $result instanceof Object) ? $result->forTemplate() : $result;
} }
/** /**
* Return the value of the field without any escaping being applied. * Return the value of the field without any escaping being applied.
*/ */
public function RAW_val($field, $arguments = null, $cache = true) { public function RAW_val($field, $arguments = null, $cache = true) {
return Convert::xml2raw($this->XML_val($field, $arguments, $cache)); return Convert::xml2raw($this->XML_val($field, $arguments, $cache));
} }
/** /**
* Return the value of a field in an SQL-safe format. * Return the value of a field in an SQL-safe format.
*/ */
public function SQL_val($field, $arguments = null, $cache = true) { public function SQL_val($field, $arguments = null, $cache = true) {
return Convert::raw2sql($this->RAW_val($field, $arguments, $cache)); return Convert::raw2sql($this->RAW_val($field, $arguments, $cache));
} }
/** /**
* Return the value of a field in a JavaScript-save format. * Return the value of a field in a JavaScript-save format.
*/ */
public function JS_val($field, $arguments = null, $cache = true) { public function JS_val($field, $arguments = null, $cache = true) {
return Convert::raw2js($this->RAW_val($field, $arguments, $cache)); return Convert::raw2js($this->RAW_val($field, $arguments, $cache));
} }
/** /**
* Return the value of a field escaped suitable to be inserted into an XML node attribute. * Return the value of a field escaped suitable to be inserted into an XML node attribute.
*/ */
public function ATT_val($field, $arguments = null, $cache = true) { public function ATT_val($field, $arguments = null, $cache = true) {
return Convert::raw2att($this->RAW_val($field, $arguments, $cache)); return Convert::raw2att($this->RAW_val($field, $arguments, $cache));
} }
/**#@-*/ /**#@-*/
/** /**
* Get an array of XML-escaped values by field name * Get an array of XML-escaped values by field name
* *
@ -514,16 +514,16 @@ class ViewableData extends Object implements IteratorAggregate {
*/ */
public function getXMLValues($fields) { public function getXMLValues($fields) {
$result = array(); $result = array();
foreach($fields as $field) { foreach($fields as $field) {
$result[$field] = $this->XML_val($field); $result[$field] = $this->XML_val($field);
} }
return $result; return $result;
} }
// ITERATOR SUPPORT ------------------------------------------------------------------------------------------------ // ITERATOR SUPPORT ------------------------------------------------------------------------------------------------
/** /**
* Return a single-item iterator so you can iterate over the fields of a single record. * Return a single-item iterator so you can iterate over the fields of a single record.
* *
@ -535,9 +535,9 @@ class ViewableData extends Object implements IteratorAggregate {
public function getIterator() { public function getIterator() {
return new ArrayIterator(array($this)); return new ArrayIterator(array($this));
} }
// UTILITY METHODS ------------------------------------------------------------------------------------------------- // UTILITY METHODS -------------------------------------------------------------------------------------------------
/** /**
* When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need * When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need
* access to itself. * access to itself.
@ -547,7 +547,7 @@ class ViewableData extends Object implements IteratorAggregate {
public function Me() { public function Me() {
return $this; return $this;
} }
/** /**
* Return the directory if the current active theme (relative to the site root). * Return the directory if the current active theme (relative to the site root).
* *
@ -562,15 +562,15 @@ class ViewableData extends Object implements IteratorAggregate {
*/ */
public function ThemeDir($subtheme = false) { public function ThemeDir($subtheme = false) {
if( if(
Config::inst()->get('SSViewer', 'theme_enabled') Config::inst()->get('SSViewer', 'theme_enabled')
&& $theme = Config::inst()->get('SSViewer', 'theme') && $theme = Config::inst()->get('SSViewer', 'theme')
) { ) {
return THEMES_DIR . "/$theme" . ($subtheme ? "_$subtheme" : null); return THEMES_DIR . "/$theme" . ($subtheme ? "_$subtheme" : null);
} }
return project(); return project();
} }
/** /**
* Get part of the current classes ancestry to be used as a CSS class. * Get part of the current classes ancestry to be used as a CSS class.
* *
@ -585,17 +585,17 @@ class ViewableData extends Object implements IteratorAggregate {
$classes = array(); $classes = array();
$classAncestry = array_reverse(ClassInfo::ancestry($this->class)); $classAncestry = array_reverse(ClassInfo::ancestry($this->class));
$stopClasses = ClassInfo::ancestry($stopAtClass); $stopClasses = ClassInfo::ancestry($stopAtClass);
foreach($classAncestry as $class) { foreach($classAncestry as $class) {
if(in_array($class, $stopClasses)) break; if(in_array($class, $stopClasses)) break;
$classes[] = $class; $classes[] = $class;
} }
// optionally add template identifier // optionally add template identifier
if(isset($this->template) && !in_array($this->template, $classes)) { if(isset($this->template) && !in_array($this->template, $classes)) {
$classes[] = $this->template; $classes[] = $this->template;
} }
return Convert::raw2att(implode(' ', $classes)); return Convert::raw2att(implode(' ', $classes));
} }
@ -607,7 +607,7 @@ class ViewableData extends Object implements IteratorAggregate {
public function Debug() { public function Debug() {
return new ViewableData_Debugger($this); return new ViewableData_Debugger($this);
} }
} }
/** /**
@ -615,12 +615,12 @@ class ViewableData extends Object implements IteratorAggregate {
* @subpackage view * @subpackage view
*/ */
class ViewableData_Customised extends ViewableData { class ViewableData_Customised extends ViewableData {
/** /**
* @var ViewableData * @var ViewableData
*/ */
protected $original, $customised; protected $original, $customised;
/** /**
* Instantiate a new customised ViewableData object * Instantiate a new customised ViewableData object
* *
@ -630,54 +630,54 @@ class ViewableData_Customised extends ViewableData {
public function __construct(ViewableData $originalObject, ViewableData $customisedObject) { public function __construct(ViewableData $originalObject, ViewableData $customisedObject) {
$this->original = $originalObject; $this->original = $originalObject;
$this->customised = $customisedObject; $this->customised = $customisedObject;
$this->original->setCustomisedObj($this); $this->original->setCustomisedObj($this);
parent::__construct(); parent::__construct();
} }
public function __call($method, $arguments) { public function __call($method, $arguments) {
if($this->customised->hasMethod($method)) { if($this->customised->hasMethod($method)) {
return call_user_func_array(array($this->customised, $method), $arguments); return call_user_func_array(array($this->customised, $method), $arguments);
} }
return call_user_func_array(array($this->original, $method), $arguments); return call_user_func_array(array($this->original, $method), $arguments);
} }
public function __get($property) { public function __get($property) {
if(isset($this->customised->$property)) { if(isset($this->customised->$property)) {
return $this->customised->$property; return $this->customised->$property;
} }
return $this->original->$property; return $this->original->$property;
} }
public function __set($property, $value) { public function __set($property, $value) {
$this->customised->$property = $this->original->$property = $value; $this->customised->$property = $this->original->$property = $value;
} }
public function hasMethod($method) { public function hasMethod($method) {
return $this->customised->hasMethod($method) || $this->original->hasMethod($method); return $this->customised->hasMethod($method) || $this->original->hasMethod($method);
} }
public function cachedCall($field, $arguments = null, $identifier = null) { public function cachedCall($field, $arguments = null, $identifier = null) {
if($this->customised->hasMethod($field) || $this->customised->hasField($field)) { if($this->customised->hasMethod($field) || $this->customised->hasField($field)) {
$result = $this->customised->cachedCall($field, $arguments, $identifier); $result = $this->customised->cachedCall($field, $arguments, $identifier);
} else { } else {
$result = $this->original->cachedCall($field, $arguments, $identifier); $result = $this->original->cachedCall($field, $arguments, $identifier);
} }
return $result; return $result;
} }
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) { public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
if($this->customised->hasField($fieldName) || $this->customised->hasMethod($fieldName)) { if($this->customised->hasField($fieldName) || $this->customised->hasMethod($fieldName)) {
return $this->customised->obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName); return $this->customised->obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName);
} }
return $this->original->obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName); return $this->original->obj($fieldName, $arguments, $forceReturnedObject, $cache, $cacheName);
} }
} }
/** /**
@ -687,12 +687,12 @@ class ViewableData_Customised extends ViewableData {
* @subpackage view * @subpackage view
*/ */
class ViewableData_Debugger extends ViewableData { class ViewableData_Debugger extends ViewableData {
/** /**
* @var ViewableData * @var ViewableData
*/ */
protected $object; protected $object;
/** /**
* @param ViewableData $object * @param ViewableData $object
*/ */
@ -720,22 +720,22 @@ class ViewableData_Debugger extends ViewableData {
if($field) return "<b>Debugging Information for {$this->class}->{$field}</b><br/>" . if($field) return "<b>Debugging Information for {$this->class}->{$field}</b><br/>" .
($this->object->hasMethod($field)? "Has method '$field'<br/>" : null) . ($this->object->hasMethod($field)? "Has method '$field'<br/>" : null) .
($this->object->hasField($field) ? "Has field '$field'<br/>" : null) ; ($this->object->hasField($field) ? "Has field '$field'<br/>" : null) ;
// debugging information for the entire class // debugging information for the entire class
$reflector = new ReflectionObject($this->object); $reflector = new ReflectionObject($this->object);
$debug = "<b>Debugging Information: all methods available in '{$this->object->class}'</b><br/><ul>"; $debug = "<b>Debugging Information: all methods available in '{$this->object->class}'</b><br/><ul>";
foreach($this->object->allMethodNames() as $method) { foreach($this->object->allMethodNames() as $method) {
// check that the method is public // check that the method is public
if($method[0] === strtoupper($method[0]) && $method[0] != '_') { if($method[0] === strtoupper($method[0]) && $method[0] != '_') {
if($reflector->hasMethod($method) && $method = $reflector->getMethod($method)) { if($reflector->hasMethod($method) && $method = $reflector->getMethod($method)) {
if($method->isPublic()) { if($method->isPublic()) {
$debug .= "<li>\${$method->getName()}"; $debug .= "<li>\${$method->getName()}";
if(count($method->getParameters())) { if(count($method->getParameters())) {
$debug .= ' <small>(' . implode(', ', $method->getParameters()) . ')</small>'; $debug .= ' <small>(' . implode(', ', $method->getParameters()) . ')</small>';
} }
$debug .= '</li>'; $debug .= '</li>';
} }
} else { } else {
@ -743,24 +743,24 @@ class ViewableData_Debugger extends ViewableData {
} }
} }
} }
$debug .= '</ul>'; $debug .= '</ul>';
if($this->object->hasMethod('toMap')) { if($this->object->hasMethod('toMap')) {
$debug .= "<b>Debugging Information: all fields available in '{$this->object->class}'</b><br/><ul>"; $debug .= "<b>Debugging Information: all fields available in '{$this->object->class}'</b><br/><ul>";
foreach($this->object->toMap() as $field => $value) { foreach($this->object->toMap() as $field => $value) {
$debug .= "<li>\$$field</li>"; $debug .= "<li>\$$field</li>";
} }
$debug .= "</ul>"; $debug .= "</ul>";
} }
// check for an extra attached data // check for an extra attached data
if($this->object->hasMethod('data') && $this->object->data() != $this->object) { if($this->object->hasMethod('data') && $this->object->data() != $this->object) {
$debug .= ViewableData_Debugger::create($this->object->data())->forTemplate(); $debug .= ViewableData_Debugger::create($this->object->data())->forTemplate();
} }
return $debug; return $debug;
} }