Debian Codegraph @

vendor/wikimedia/remex-html/src/Serializer/Formatter.php

raw
1 <?php
2
3 namespace Wikimedia\RemexHtml\Serializer;
4
5 /**
6 * The interface for classes that help Serializer to convert nodes to strings.
7 * Serializer assumes that the return values of these functions can be
8 * concatenated to make a document.
9 *
10 * It is not safe to assume that the methods will be called in any particular
11 * order, or that the return values will actually be retained in the final
12 * Serializer result.
13 */
14 interface Formatter {
15 /**
16 * Get a string which starts the document
17 *
18 * @param string|null $fragmentNamespace
19 * @param string|null $fragmentName
20 * @return string
21 */
22 public function startDocument( $fragmentNamespace, $fragmentName );
23
24 /**
25 * Encode the given character substring
26 *
27 * @param SerializerNode $parent The parent of the text node (at creation time)
28 * @param string $text
29 * @param int $start The offset within $text
30 * @param int $length The number of bytes within $text
31 * @return string
32 */
33 public function characters( SerializerNode $parent, $text, $start, $length );
34
35 /**
36 * Encode the given element
37 *
38 * @param SerializerNode $parent The parent of the node (when it is closed)
39 * @param SerializerNode $node The element to encode
40 * @param string|null $contents The previously-encoded contents, or null
41 * for a void element. Void elements can be serialized as self-closing
42 * tags.
43 * @return string
44 */
45 public function element( SerializerNode $parent, SerializerNode $node, $contents );
46
47 /**
48 * Encode a comment
49 * @param SerializerNode $parent The parent of the node (at creation time)
50 * @param string $text The inner text of the comment
51 * @return string
52 */
53 public function comment( SerializerNode $parent, $text );
54
55 /**
56 * Encode a doctype. This event occurs when the source document has a doctype,
57 * it can return an empty string if the formatter wants to use its own doctype.
58 *
59 * @param string $name The doctype name, usually "html"
60 * @param string $public The PUBLIC identifier
61 * @param string $system The SYSTEM identifier
62 * @return string
63 */
64 public function doctype( $name, $public, $system );
65 }