コード例 #1
0
 /**
  * Renders a HTML or HTML fragment.
  *
  * @param string                  $file
  * @param Piece_Unity_ViewElement &$viewElement
  * @throws PIECE_UNITY_ERROR_NOT_FOUND
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  */
 function render($file, &$viewElement)
 {
     $flexy =& new HTML_Template_Flexy($this->_options);
     $resultOfCompile = $flexy->compile($file);
     if (PEAR::isError($resultOfCompile)) {
         if ($flexy->currentTemplate === false) {
             Piece_Unity_Error::pushPEARError($resultOfCompile, PIECE_UNITY_ERROR_NOT_FOUND, "The HTML template file [ {$file} ] is not found or not readable.");
             return;
         }
         Piece_Unity_Error::pushPEARError($resultOfCompile, PIECE_UNITY_ERROR_INVOCATION_FAILED, 'Failed to invoke HTML_Template_Flexy::compile() for any reasons.');
         return;
     }
     $viewElements = $viewElement->getElements();
     if (is_null($this->_controller)) {
         $this->_controller = (object) $viewElements;
     } else {
         foreach (array_keys($viewElements) as $element) {
             if (!is_object($viewElements[$element])) {
                 $this->_controller->{$element} = $viewElements[$element];
             } else {
                 $this->_controller->{$element} =& $viewElements[$element];
             }
         }
     }
     $flexyElement =& new Piece_Unity_Service_FlexyElement();
     $flexyElement->setViewElement($viewElement);
     $resultOfOutputObject = $flexy->outputObject($this->_controller, $flexyElement->createFormElements());
     if (PEAR::isError($resultOfOutputObject)) {
         Piece_Unity_Error::pushPEARError($resultOfOutputObject, PIECE_UNITY_ERROR_INVOCATION_FAILED, 'Failed to invoke HTML_Template_Flexy::outputObject() for any reasons.');
     }
 }
コード例 #2
0
 /**
  * Encode a given value with PEAR::HTML_AJAX.
  *
  * @param mixed $value
  * @return string JSON string representation of a given value
  *                or false if error ocurrs.
  * @throws PIECE_UNITY_ERROR_INVOCATION_FAILED
  * @static
  */
 function encodeWithHTMLAJAX($value)
 {
     include_once 'PEAR.php';
     $encoder =& new HTML_AJAX_JSON();
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     $json = $encoder->encode($value);
     PEAR::staticPopErrorHandling();
     if (HTML_AJAX_JSON::isError($json)) {
         Piece_Unity_Error::pushPEARError($json, PIECE_UNITY_ERROR_INVOCATION_FAILED, "Failed to invoke the plugin [ {$this->_name} ].");
         return;
     }
     return $json;
 }