示例#1
0
文件: Flexy.php 项目: roojs/pear
 /**
  *   Outputs an object as $t 
  *
  *   for example the using simpletags the object's variable $t->test
  *   would map to {test}
  *
  *   @version    01/12/14
  *   @access     public
  *   @author     Alan Knowles
  *   @param    object   to output  
  *   @param    array  HTML_Template_Flexy_Elements (or any object that implements toHtml())
  *   @return     none
  */
 function outputObject(&$t, $elements = array())
 {
     if (!is_array($elements)) {
         return $this->raiseError('second Argument to HTML_Template_Flexy::outputObject() was an ' . gettype($elements) . ', not an array', HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS, HTML_TEMPLATE_FLEXY_ERROR_DIE);
     }
     if (@$this->options['debug']) {
         echo "output {$this->compiledTemplate}<BR>";
     }
     // this may disappear later it's a Backwards Compatibility fudge to try
     // and deal with the first stupid design decision to not use a second argument
     // to the method.
     if (count($this->elements) && !count($elements)) {
         $elements = $this->elements;
     }
     // end depreciated code
     $this->elements = $this->getElements();
     // Overlay values from $elements to $this->elements (which is created from the template)
     // Remove keys with no corresponding value.
     foreach ($elements as $k => $v) {
         // Remove key-value pair from $this->elements if hasn't a value in $elements.
         if (!$v) {
             unset($this->elements[$k]);
         }
         // Add key-value pair to $this->$elements if it's not there already.
         if (!isset($this->elements[$k])) {
             $this->elements[$k] = $v;
             continue;
         }
         // Call the clever element merger - that understands form values and
         // how to display them...
         $this->elements[$k] = $this->elements[$k]->merge($v);
     }
     //echo '<PRE>'; print_r(array($elements,$this->elements));
     // we use PHP's error handler to hide errors in the template.
     // use $options['strict'] - if you want to force declaration of
     // all variables in the template
     $_error_reporting = false;
     if (!$this->options['strict']) {
         $_error_reporting = error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
     }
     if (!is_readable($this->compiledTemplate)) {
         return $this->raiseError("Could not open the template: <b>'{$this->compiledTemplate}'</b><BR>" . "Please check the file permissions on the directory and file ", HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_DIE);
     }
     // are we using the assign api!
     if (isset($this->assign)) {
         if (!$t) {
             $t = (object) $this->assign->variables;
         }
         extract($this->assign->variables);
         foreach (array_keys($this->assign->references) as $_k) {
             ${$_k} =& $this->assign->references[$_k];
         }
     }
     // used by Flexy Elements etc..
     // note that we are using __ prefix, as this get's exposed to the running template..
     $__old_engine = self::$activeEngine;
     $this->initializeTranslator();
     self::$activeEngine = $this;
     //?? not needed?
     $GLOBALS['_HTML_TEMPLATE_FLEXY']['options'] = $this->options;
     // initialize the translator..
     include $this->compiledTemplate;
     self::$activeEngine = $__old_engine;
     // Return the error handler to its previous state.
     if ($_error_reporting !== false) {
         error_reporting($_error_reporting);
     }
 }