예제 #1
0
 /**
  * Set a template variable
  *   
  * @param string|array $name name of the variable
  * @param string|integer|array|TemplateEngine  $value value of variable
  * @param boolean $local specify if value is in local scope or static 
  * @param boolean $force  force to set a variable even it is locked
  * @return void
  * @access public
  */
 public function setVariable($name, $value = null, $local = true, $force = false)
 {
     // do not allow to replace locekd variables
     if (!$force && in_array($name, $this->lockedVars)) {
         return;
     }
     //TODO remove debuggin
     if (false && $name == 'tpl_content') {
         $trace = debug_backtrace();
         $caller = array_shift($trace);
         echo 'called by ' . $caller['function'];
         if (isset($caller['class'])) {
             echo 'in ' . $caller['class'];
         }
         echo "\n<br />";
     }
     if (is_array($name)) {
         if ($local) {
             $this->localVars = array_merge($this->localVars, $name);
         } else {
             self::$vars = array_merge(self::$vars, $name);
         }
     } else {
         $key = $name;
         if (is_object($value)) {
             // value is an object, check if it is a template object
             if (__CLASS__ != get_class($value)) {
                 return;
             }
             // generate text from template
             $value = $value->fetch();
         }
         if ($local) {
             $this->localVars[$name] = $value;
         } else {
             self::$vars[$name] = $value;
         }
     }
 }