Permalink
Browse files

BUGFIX: Allow template globals to be used in both object and value co…

…ntexts (e.g. $Now.Year)

BUGFIX: Allow template globals to return objects as well as values.
  • Loading branch information...
1 parent e443ec5 commit acdd07ac6f38872d4ac9b96d3bcd7adce55f3bff @sminnee sminnee committed Mar 16, 2012
Showing with 26 additions and 12 deletions.
  1. +26 −12 view/SSViewer.php
View
@@ -52,7 +52,12 @@ function resetLocalScope(){
array_splice($this->itemStack, $this->localIndex+1);
}
- function obj($name){
+ function getObj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
+ $on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
+ return $on->obj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
+ }
+
+ function obj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null){
switch ($name) {
case 'Up':
@@ -64,10 +69,7 @@ function obj($name){
break;
default:
- $on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
-
- $arguments = func_get_args();
- $this->item = call_user_func_array(array($on, 'obj'), $arguments);
+ $this->item = $this->getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
$this->itemIterator = null;
$this->upIndex = $this->currentIndex ? $this->currentIndex : count($this->itemStack)-1;
@@ -389,21 +391,33 @@ function getInjectedValue($property, $params, $cast = true) {
// If we want to provide a casted object, look up what type object to use
if ($cast) {
- // Get the object to cast as
- $casting = isset($source['casting']) ? $source['casting'] : null;
- // If not provided, use default
- if (!$casting) $casting = Object::get_static('ViewableData', 'default_cast');
+ // If the handler returns an object, then we don't need to cast.
+ if(is_object($res['value'])) {
+ $res['obj'] = $res['value'];
- $obj = new $casting($property);
- $obj->setValue($res['value']);
+ } else {
+ // Get the object to cast as
+ $casting = isset($source['casting']) ? $source['casting'] : null;
+ // If not provided, use default
+ if (!$casting) $casting = Object::get_static('ViewableData', 'default_cast');
- $res['obj'] = $obj;
+ $obj = new $casting($property);
+ $obj->setValue($res['value']);
+
+ $res['obj'] = $obj;
+ }
}
return $res;
}
}
+ function getObj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
+ $result = $this->getInjectedValue($name, (array)$arguments);
+ if($result) return $result['obj'];
+ else return parent::getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
+ }
+
function __call($name, $arguments) {
//extract the method name and parameters
$property = $arguments[0]; //the name of the function being called

0 comments on commit acdd07a

Please sign in to comment.