/** * Return the object version of the given field/method. * @param string $fieldName The name of the field/method. * @param array $args The arugments. * @param boolean $forceReturnObject If true, this method will *always* return an object. If there's * no sensible one available, it will return new ViewableData() * @return mixed; */ public function obj($fieldName, $args = null, $forceReturnObject = false) { if (isset($_GET['debug_profile'])) { Profiler::mark("template({$fieldName})", " on {$this->class} object"); } if ($args) { $identifier = $fieldName . ',' . implode(',', $args); } else { $identifier = $fieldName; } // Fix for PHP 5.3 - $args cannot be null if (is_null($args)) { $args = array(); } if (isset($this->_object_cache[$identifier])) { $fieldObj = $this->_object_cache[$identifier]; } else { if ($this->hasMethod($fieldName)) { $val = call_user_func_array(array(&$this, $fieldName), $args); } else { $val = $this->{$fieldName}; } $this->_natural_cache[$identifier] = $val; if (is_object($val)) { $fieldObj = $val; } else { $helperPair = $this->castingHelperPair($fieldName); if (!$helperPair && $this->failover) { $helperPair = $this->failover->castingHelperPair($fieldName); } $constructor = $helperPair['castingHelper']; if ($constructor) { $fieldObj = eval($constructor); if ($this->hasMethod('getAllFields')) { $fieldObj->setValue($val, $this->getAllFields()); } else { $fieldObj->setValue($val); } } } $this->_object_cache[$identifier] = isset($fieldObj) ? $fieldObj : null; } if (!isset($fieldObj) && $forceReturnObject) { $fieldObj = new ViewableData(); } if (isset($_GET['debug_profile'])) { Profiler::unmark("template({$fieldName})", " on {$this->class} object"); } return isset($fieldObj) ? $fieldObj : null; }