]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / ConfigSchema / Builder / Xml.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Converts HTMLPurifier_ConfigSchema_Interchange to an XML format,\r
5 * which can be further processed to generate documentation.\r
6 */\r
7class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter\r
8{\r
9\r
10 /**\r
11 * @type HTMLPurifier_ConfigSchema_Interchange\r
12 */\r
13 protected $interchange;\r
14\r
15 /**\r
16 * @type string\r
17 */\r
18 private $namespace;\r
19\r
20 /**\r
21 * @param string $html\r
22 */\r
23 protected function writeHTMLDiv($html)\r
24 {\r
25 $this->startElement('div');\r
26\r
27 $purifier = HTMLPurifier::getInstance();\r
28 $html = $purifier->purify($html);\r
29 $this->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml');\r
30 $this->writeRaw($html);\r
31\r
32 $this->endElement(); // div\r
33 }\r
34\r
35 /**\r
36 * @param mixed $var\r
37 * @return string\r
38 */\r
39 protected function export($var)\r
40 {\r
41 if ($var === array()) {\r
42 return 'array()';\r
43 }\r
44 return var_export($var, true);\r
45 }\r
46\r
47 /**\r
48 * @param HTMLPurifier_ConfigSchema_Interchange $interchange\r
49 */\r
50 public function build($interchange)\r
51 {\r
52 // global access, only use as last resort\r
53 $this->interchange = $interchange;\r
54\r
55 $this->setIndent(true);\r
56 $this->startDocument('1.0', 'UTF-8');\r
57 $this->startElement('configdoc');\r
58 $this->writeElement('title', $interchange->name);\r
59\r
60 foreach ($interchange->directives as $directive) {\r
61 $this->buildDirective($directive);\r
62 }\r
63\r
64 if ($this->namespace) {\r
65 $this->endElement();\r
66 } // namespace\r
67\r
68 $this->endElement(); // configdoc\r
69 $this->flush();\r
70 }\r
71\r
72 /**\r
73 * @param HTMLPurifier_ConfigSchema_Interchange_Directive $directive\r
74 */\r
75 public function buildDirective($directive)\r
76 {\r
77 // Kludge, although I suppose having a notion of a "root namespace"\r
78 // certainly makes things look nicer when documentation is built.\r
79 // Depends on things being sorted.\r
80 if (!$this->namespace || $this->namespace !== $directive->id->getRootNamespace()) {\r
81 if ($this->namespace) {\r
82 $this->endElement();\r
83 } // namespace\r
84 $this->namespace = $directive->id->getRootNamespace();\r
85 $this->startElement('namespace');\r
86 $this->writeAttribute('id', $this->namespace);\r
87 $this->writeElement('name', $this->namespace);\r
88 }\r
89\r
90 $this->startElement('directive');\r
91 $this->writeAttribute('id', $directive->id->toString());\r
92\r
93 $this->writeElement('name', $directive->id->getDirective());\r
94\r
95 $this->startElement('aliases');\r
96 foreach ($directive->aliases as $alias) {\r
97 $this->writeElement('alias', $alias->toString());\r
98 }\r
99 $this->endElement(); // aliases\r
100\r
101 $this->startElement('constraints');\r
102 if ($directive->version) {\r
103 $this->writeElement('version', $directive->version);\r
104 }\r
105 $this->startElement('type');\r
106 if ($directive->typeAllowsNull) {\r
107 $this->writeAttribute('allow-null', 'yes');\r
108 }\r
109 $this->text($directive->type);\r
110 $this->endElement(); // type\r
111 if ($directive->allowed) {\r
112 $this->startElement('allowed');\r
113 foreach ($directive->allowed as $value => $x) {\r
114 $this->writeElement('value', $value);\r
115 }\r
116 $this->endElement(); // allowed\r
117 }\r
118 $this->writeElement('default', $this->export($directive->default));\r
119 $this->writeAttribute('xml:space', 'preserve');\r
120 if ($directive->external) {\r
121 $this->startElement('external');\r
122 foreach ($directive->external as $project) {\r
123 $this->writeElement('project', $project);\r
124 }\r
125 $this->endElement();\r
126 }\r
127 $this->endElement(); // constraints\r
128\r
129 if ($directive->deprecatedVersion) {\r
130 $this->startElement('deprecated');\r
131 $this->writeElement('version', $directive->deprecatedVersion);\r
132 $this->writeElement('use', $directive->deprecatedUse->toString());\r
133 $this->endElement(); // deprecated\r
134 }\r
135\r
136 $this->startElement('description');\r
137 $this->writeHTMLDiv($directive->description);\r
138 $this->endElement(); // description\r
139\r
140 $this->endElement(); // directive\r
141 }\r
142}\r
143\r
144// vim: et sw=4 sts=4\r