Example #1
1
 /**
  * draw
  *
  * Try draw output layout
  *
  * @return null
  */
 public static function draw()
 {
     $renderTries = 2;
     while ($renderTries--) {
         try {
             ob_start();
             // txt context
             if (self::$_outputContext == 'txt') {
                 Request::addHeader('Content-Type: text/plain');
                 $raw = TextPlainOutput::getContent(self::$_data);
                 // json context
             } else {
                 if (self::$_outputContext == 'json') {
                     Request::addHeader('Content-Type: application/json');
                     $raw = json_encode(self::$_data ? self::$_data : new StdClass());
                     // xml context
                 } else {
                     if (self::$_outputContext == 'xml') {
                         Request::addHeader('Content-Type: application/xml');
                         $raw = XmlOutput::getContent(self::$_data, self::$_XSDSchema, self::$_docType);
                         // html context error
                     } else {
                         if (!self::$_layout) {
                             throw new SystemErrorException(array('title' => 'View error', 'description' => 'Layout is not set'));
                             // html context
                         } else {
                             Request::addHeader('Content-Type: text/html; charset=utf-8');
                             self::_normalizeHtmlContext();
                             extract(self::$_protectedData);
                             extract(self::$_data);
                         }
                     }
                 }
             }
             // set non-html context raw layout
             if (self::$_outputContext != 'html') {
                 self::$_layout = 'raw.phtml';
             }
             require self::$_layout;
         } catch (Exception $e) {
             ob_clean();
             self::assignException($e);
             continue;
         }
         $layoutContent = ob_get_clean();
         break;
     }
     if (!isset($layoutContent) && isset($e)) {
         UnexpectedException::take($e, true);
     }
     Request::sendHeaders();
     echo $layoutContent;
 }
Example #2
0
 /**
  * getContent
  *
  * Generate XML string
  *
  * @param  mixed  $data    Input data
  * @param  array  $schema  XSD-schema exposed as array
  * @param  mixed  $docType Doctype and XML namespace
  * @return string          Generated XML string
  */
 public static function getContent($data, array $schema, $docType)
 {
     if ($docType === null) {
         self::$_xmlDOM = new DOMDocument("1.0", "utf-8");
     } else {
         $imp = new DOMImplementation();
         $dtd = $imp->createDocumentType($docType['name'], '', $docType['id']);
         self::$_xmlDOM = $imp->createDocument("", "", $dtd);
         self::$_xmlDOM->encoding = 'utf-8';
     }
     self::$_xmlDOM->formatOutput = true;
     self::$_xmlDOM->substituteEntities = true;
     $mainAttributes = array();
     if (array_key_exists('attributes', $schema)) {
         $mainAttributes = $schema['attributes'];
     }
     if (!$data || sizeof($data) > 1) {
         $data = array($data);
     }
     self::_createXmlChildren($data, self::$_xmlDOM, $mainAttributes, array($schema));
     return self::$_xmlDOM->saveXML();
 }