protected function computeMetas() { $xyl = new Xyl(new File\Read($this->_file->getPathname()), new Http\Response(), new Xyl\Interpreter\Html(), $this->_router); $ownerDocument = $xyl->readDOM()->ownerDocument; $xpath = new DOMXpath($ownerDocument); $query = $xpath->query('/processing-instruction(\'xyl-meta\')'); for ($i = 0, $m = $query->length; $i < $m; ++$i) { $item = $query->item($i); $meta = new Xml\Attribute($item->data); $name = $meta->readAttribute('name'); $value = $meta->readAttribute('value'); if (false === in_array($name, static::LIST_OF_METAS)) { continue; } $this->_metas[$name] = $value; $item->parentNode->removeChild($item); } $buffer = new Stringbuffer\Read(); $buffer->initializeWith($xyl->readXML()); $this->_streamName = $buffer->getStreamName(); return; }
/** * Compute <?xyl-stylesheet?> processing-instruction. * * @param \DOMDocument $ownerDocument Document that ownes PIs. * @return void */ protected function computeStylesheet(\DOMDocument $ownerDocument) { $xpath = new \DOMXPath($ownerDocument); $xyl_style = $xpath->query('/processing-instruction(\'xyl-stylesheet\')'); unset($xpath); if (0 === $xyl_style->length) { return; } for ($i = 0, $m = $xyl_style->length; $i < $m; ++$i) { $item = $xyl_style->item($i); $styleParsed = new Xml\Attribute($item->data); if (true === $styleParsed->attributeExists('href')) { $href = $this->computeLink($styleParsed->readAttribute('href'), true); if (true === $styleParsed->attributeExists('position')) { $position = max(0, (int) static::evaluateXPath(str_replace('last()', ($k = key($this->_stylesheets)) ? $k + 1 : 0, $styleParsed->readAttribute('position')))); if (isset($this->_stylesheets[$position])) { $handle = []; foreach ($this->_stylesheets as $i => $foo) { if ($position > $i) { $handle[$i] = $foo; unset($this->_stylesheets[$i]); } else { break; } } $handle[$position] = $href; foreach ($this->_stylesheets as $i => $foo) { if ($i === $position) { $handle[$position = $i + 1] = $foo; unset($this->_stylesheets[$i]); } else { break; } } $this->_stylesheets = $handle + $this->_stylesheets; } else { $this->_stylesheets[$position] = $href; ksort($this->_stylesheets, SORT_NUMERIC); } } else { $this->_stylesheets[] = $href; } } $ownerDocument->removeChild($item); unset($styleParsed); } return; }
/** * Compute <?xyl-link?> processing-instruction. * * @param \DOMDocument $ownerDocument Document that ownes PIs. * @return void */ protected function computeDocumentLinks(\DOMDocument $ownerDocument) { $xpath = new \DOMXPath($ownerDocument); $xyl_link = $xpath->query('/processing-instruction(\'xyl-link\')'); unset($xpath); if (0 === $xyl_link->length) { return; } for ($i = 0, $m = $xyl_link->length; $i < $m; ++$i) { $item = $xyl_link->item($i); $documentLink = new Xml\Attribute($item->data); if (true === $documentLink->attributeExists('href')) { $documentLink->writeAttribute('href', $this->computeLink($documentLink->readAttribute('href'), true)); } $this->_documentLinks[] = $documentLink; $ownerDocument->removeChild($item); } return; }