Example #1
0
 public function output($data = null, $document = false)
 {
     $headers = [];
     $elementData = new \Transphporm\Hook\ElementData(new \SplObjectStorage(), $data);
     $data = new FunctionSet($elementData);
     $cachedOutput = $this->loadTemplate();
     //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->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>');
     $valueParser = new Parser\Value($data);
     $config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($data, $template->getPrefix()), $headers, $this->baseDir);
     foreach ($this->modules as $module) {
         $module->load($config);
     }
     $this->processRules($template, $config);
     $result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)];
     $this->cache->write($this->template, $result);
     $result['body'] = $this->doPostProcessing($template)->output($document);
     return (object) $result;
 }
Example #2
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];
 }