Example #1
0
 public function output($data = null, $document = false)
 {
     $locale = $this->getLocale();
     $data = new Hook\DataFunction(new \SplObjectStorage(), $data, $locale, $this->baseDir);
     $headers = [];
     $this->registerProperties($this->getBasicProperties($data, $locale, $headers));
     //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
     $template = new Template($this->isFile ? $this->template : '<template>' . $this->template . '</template>');
     $rules = (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
     foreach ($rules as $rule) {
         $hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data);
         foreach ($this->registeredProperties as $properties) {
             $hook->registerProperties($properties);
         }
         $template->addHook($rule->query, $hook);
     }
     $output = $template->output($document);
     return (object) ['headers' => $headers, 'body' => $output];
 }