1 | <?php |
||
19 | class Parser implements ParserInterface |
||
20 | { |
||
21 | /** |
||
22 | * Inline code template |
||
23 | */ |
||
24 | private const CODE_INLINE = '<code>%s</code>'; |
||
25 | |||
26 | /** |
||
27 | * Block code template |
||
28 | */ |
||
29 | private const CODE_BLOCK = '<code language="%s">%s</code>'; |
||
30 | |||
31 | /** |
||
32 | * User without avatar |
||
33 | */ |
||
34 | private const USER_SHORT = '<user id="%s" name="%s">%s</user>'; |
||
35 | |||
36 | /** |
||
37 | * User with avatar |
||
38 | */ |
||
39 | private const USER_FULL = '<user id="%s" name="%s" avatar="%s">%s</user>'; |
||
40 | |||
41 | /** |
||
42 | * @var array|UserInterface[] |
||
43 | */ |
||
44 | private $mentions = []; |
||
45 | |||
46 | /** |
||
47 | * @param string $html |
||
48 | * @param array|UserInterface[] $mentions |
||
49 | * @return string |
||
50 | */ |
||
51 | public function parse(string $html, array $mentions): string |
||
63 | |||
64 | /** |
||
65 | * @param string $html |
||
66 | * @return string |
||
67 | */ |
||
68 | private function removeUnusedTags(string $html): string |
||
72 | |||
73 | /** |
||
74 | * @param string $html |
||
75 | * @return \DOMNode |
||
76 | */ |
||
77 | private function createRoot(string $html): \DOMNode |
||
86 | |||
87 | /** |
||
88 | * @param \DOMNode $root |
||
89 | * @return string |
||
90 | */ |
||
91 | private function transformXml(\DOMNode $root): string |
||
106 | |||
107 | /** |
||
108 | * @param \DOMElement|\DOMText $child |
||
109 | * @return string |
||
110 | */ |
||
111 | private function transformChildren($child): string |
||
127 | |||
128 | /** |
||
129 | * @param \DOMElement $user |
||
130 | * @return string |
||
131 | */ |
||
132 | private function parseUser(\DOMElement $user): string |
||
148 | |||
149 | /** |
||
150 | * @param \DOMElement $code |
||
151 | * @return string |
||
152 | */ |
||
153 | private function parseCode(\DOMElement $code): string |
||
163 | } |
||
164 |