Esempio n. 1
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;
     }
 }
Esempio n. 2
0
 /**
  * This method returns the processed resource as a collection.
  *
  * @access public
  * @param string $path                                      the path to the value to be returned
  * @return mixed                                            the resource as a collection
  */
 public function read($path = null)
 {
     $buffer = file_get_contents($this->file);
     if ($this->metadata['bom']) {
         $buffer = preg_replace('/^' . pack('H*', 'EFBBBF') . '/', '', $buffer);
     }
     if (!preg_match('/^<\\?xml\\s+.+\\?>/', $buffer)) {
         $buffer = Core\Data\XML::declaration(Core\Data\Charset::UTF_8_ENCODING) . "\n" . $buffer;
     }
     $document = new \DOMDocument();
     $document->substituteEntities = false;
     $document->loadXML($buffer);
     $collection = $this->parseWDDXPacketElement($document);
     if ($path !== null) {
         $collection = Config\Helper::factory($collection)->getValue($path);
     }
     return $collection;
 }