diff options
author | Matt Farina <[email protected]> | 2013-09-26 12:23:22 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-09-26 12:23:22 -0400 |
commit | 273235b13c072713052e5845ff107e9f197c4d61 (patch) | |
tree | 9b808d9b27de30e54869de6ff45243ba1f4e59ca /src/HTML5/Serializer/Serializer.php | |
parent | 36d188ad4562abdfe4cd7901c040cafbfe708a2c (diff) |
The serializer was a wrapper for serializing the same way html5 at the top level was a wrapper for parsing. Moved the serializing interface to be in the same form as the parser for consistency.
Diffstat (limited to 'src/HTML5/Serializer/Serializer.php')
-rw-r--r-- | src/HTML5/Serializer/Serializer.php | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/src/HTML5/Serializer/Serializer.php b/src/HTML5/Serializer/Serializer.php deleted file mode 100644 index 7d1e7b2..0000000 --- a/src/HTML5/Serializer/Serializer.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php -/** - * A simple serializer that walks the DOM tree and outputs HTML5. - */ -namespace HTML5\Serializer; - -use \HTML5\Serializer\OutputRules; - -/** - * Transform a DOM into an HTML5 document. - * - * This provides a serializer that roughly follows the save and load API - * in the native PHP DOM implementation. - * - * For reference, see DOMDocument::save, DOMDocument::saveXML, - * DOMDocument::saveHTML and DOMDocument::saveHTMLFile. - */ -class Serializer { - protected $dom; - protected $options = array(); - - /** - * Create a serializer. - * - * This takes a DOM-like data structure. It SHOULD treat the - * DOMNode as an interface, but this does not do type checking. - * - * @param DOMNode $dom - * A DOMNode-like object. Typically, a DOMDocument should be passed. - * @param array $options - * Options that can be passed into the serializer. These include: - * - format: a bool value to specify if formatting (e.g. add indentation) - * should be used on the output. Defaults to TRUE. - * - encode: Text written to the output is escaped by default and not all - * entities are encoded. If this is set to TRUE all entities will be encoded. - * Defaults to FALSE. - */ - public function __construct($dom, $options = array()) { - $this->dom = $dom; - $this->options = $options; - } - - /** - * Save to a file. - * - * @param mixed $filename - * A file handle resource or the - * full name to the file. This will overwrite the contents of - * any file that it finds. - */ - public function save($filename) { - $close = TRUE; - if (is_resource($filename)) { - $file = $filename; - $close = FALSE; - } - else { - $file = fopen($filename, 'w'); - } - $rules = new OutputRules($file, $this->options); - $trav = new Traverser($this->dom, $file, $rules, $this->options); - - $trav->walk(); - - if ($close) { - fclose($file); - } - } - - /** - * Return the DOM as an HTML5 string. - */ - public function saveHTML() { - // We buffer into a temp-file backed memory map. This may or may not be - // faster than writing directly to a string, but it makes the interface - // consistant and will keep memory consumption lower (2MB max for the file - // buffer). - $stream = fopen('php://temp', 'w'); - $this->save($stream); - return stream_get_contents($stream, -1, 0); - } -} |