Ejemplo n.º 1
0
 /**
  * This method renders the data for the writer.
  *
  * @access public
  * @return string                                           the processed data
  */
 public function render()
 {
     $object_exporter = new Spring\XMLObjectExporter($this->data);
     $object_exporter->encoding = $this->metadata['encoding'];
     $object_exporter->prototype = $this->metadata['prototype'];
     $spring_xml = $object_exporter->render();
     if (!empty($this->metadata['minify'])) {
         $spring_xml = Minify\XML::minify($spring_xml, $this->metadata['minify']);
     }
     return $spring_xml;
 }
Ejemplo n.º 2
0
 /**
  * This method renders the data for the writer.
  *
  * @access public
  * @return string                                           the data as string
  * @throws \Exception                                       indicates a problem occurred
  *                                                          when generating the template
  */
 public function render()
 {
     $metadata = $this->metadata;
     $declaration = $metadata['declaration'] ? Core\Data\XML::declaration($metadata['encoding'][1], $metadata['standalone']) . $metadata['eol'] : '';
     if (!empty($metadata['template'])) {
         $file = new IO\File($metadata['template']);
         $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($file->getFilePath()), 'escape' => function ($string) use($metadata) {
             $string = Core\Data\Charset::encode($string, $metadata['encoding'][0], $metadata['encoding'][1]);
             $string = Core\Data\XML::entities($string);
             return $string;
         }));
         ob_start();
         try {
             echo $declaration;
             echo $mustache->render($file->getFileName(), $this->data);
         } catch (\Exception $ex) {
             ob_end_clean();
             throw $ex;
         }
         $template = ob_get_clean();
         if (!empty($metadata['minify'])) {
             $template = Minify\XML::minify($template, $metadata['minify']);
         }
         return $template;
     } else {
         ob_start();
         try {
             $document = new \DOMDocument();
             $document->formatOutput = true;
             $this->toXML($document, $document, $this->data);
             echo $declaration;
             echo $document->saveXML();
         } catch (\Exception $ex) {
             ob_end_clean();
             throw $ex;
         }
         $template = ob_get_clean();
         return $template;
     }
 }