@@ -24,9 +24,9 @@ |
||
24 | 24 | const ERROR_CANNOT_UNSERIALIZE_ERROR_DATA = 57201; |
25 | 25 | const ERROR_ERROR_DATA_KEY_MISSING = 57202; |
26 | 26 | |
27 | - /** |
|
28 | - * @var \LibXMLError |
|
29 | - */ |
|
27 | + /** |
|
28 | + * @var \LibXMLError |
|
29 | + */ |
|
30 | 30 | private $error; |
31 | 31 | |
32 | 32 | private static $requiredKeys = array( |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $data = @json_decode($serialized, true); |
48 | 48 | |
49 | - if(!is_array($data)) |
|
49 | + if (!is_array($data)) |
|
50 | 50 | { |
51 | 51 | throw new XMLHelper_Exception( |
52 | 52 | 'Could not unserialize error data', |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | |
73 | 73 | private static function checkErrorData(array $data) : void |
74 | 74 | { |
75 | - foreach(self::$requiredKeys as $key) |
|
75 | + foreach (self::$requiredKeys as $key) |
|
76 | 76 | { |
77 | - if(!array_key_exists($key, $data)) |
|
77 | + if (!array_key_exists($key, $data)) |
|
78 | 78 | { |
79 | 79 | throw new XMLHelper_Exception( |
80 | 80 | 'Required key missing in error data', |
@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | { |
37 | 37 | const ERROR_STRING_ALREADY_HAS_BODY_TAG = 57001; |
38 | 38 | |
39 | - /** |
|
40 | - * @var \DOMElement |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var \DOMElement |
|
41 | + */ |
|
42 | 42 | private $bodyNode; |
43 | 43 | |
44 | - /** |
|
45 | - * @var XMLHelper_DOMErrors |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var XMLHelper_DOMErrors |
|
46 | + */ |
|
47 | 47 | private $errors; |
48 | 48 | |
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | 52 | private static $htmlTemplate = |
53 | 53 | '<!DOCTYPE html>'. |
54 | 54 | '<html>'. |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | '</body>'. |
61 | 61 | '</html>'; |
62 | 62 | |
63 | - /** |
|
64 | - * @var \DOMDocument |
|
65 | - */ |
|
63 | + /** |
|
64 | + * @var \DOMDocument |
|
65 | + */ |
|
66 | 66 | private $dom; |
67 | 67 | |
68 | 68 | private function __construct(string $html) |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | $this->load($html); |
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * Creates an HTML loader from an HTML fragment (without |
|
75 | - * doctype, head and body elements). |
|
76 | - * |
|
77 | - * @param string $fragment |
|
78 | - * @return XMLHelper_HTMLLoader |
|
79 | - */ |
|
73 | + /** |
|
74 | + * Creates an HTML loader from an HTML fragment (without |
|
75 | + * doctype, head and body elements). |
|
76 | + * |
|
77 | + * @param string $fragment |
|
78 | + * @return XMLHelper_HTMLLoader |
|
79 | + */ |
|
80 | 80 | public static function loadFragment(string $fragment) : XMLHelper_HTMLLoader |
81 | 81 | { |
82 | 82 | self::checkFragment($fragment); |
@@ -87,24 +87,24 @@ discard block |
||
87 | 87 | return new XMLHelper_HTMLLoader($pseudoHTML); |
88 | 88 | } |
89 | 89 | |
90 | - /** |
|
91 | - * Creates an HTML loader from a full HTML document (including |
|
92 | - * doctype, head and body elements). |
|
93 | - * |
|
94 | - * @param string $html |
|
95 | - * @return XMLHelper_HTMLLoader |
|
96 | - */ |
|
90 | + /** |
|
91 | + * Creates an HTML loader from a full HTML document (including |
|
92 | + * doctype, head and body elements). |
|
93 | + * |
|
94 | + * @param string $html |
|
95 | + * @return XMLHelper_HTMLLoader |
|
96 | + */ |
|
97 | 97 | public static function loadHTML(string $html) : XMLHelper_HTMLLoader |
98 | 98 | { |
99 | 99 | return new XMLHelper_HTMLLoader($html); |
100 | 100 | } |
101 | 101 | |
102 | - /** |
|
103 | - * Verifies that the fragment does not already contain a body element or doctype. |
|
104 | - * |
|
105 | - * @param string $fragment |
|
106 | - * @throws XMLHelper_Exception |
|
107 | - */ |
|
102 | + /** |
|
103 | + * Verifies that the fragment does not already contain a body element or doctype. |
|
104 | + * |
|
105 | + * @param string $fragment |
|
106 | + * @throws XMLHelper_Exception |
|
107 | + */ |
|
108 | 108 | private static function checkFragment(string $fragment) : void |
109 | 109 | { |
110 | 110 | if(!stristr($fragment, '<body') && !stristr($fragment, 'doctype')) |
@@ -142,65 +142,65 @@ discard block |
||
142 | 142 | return $this->bodyNode; |
143 | 143 | } |
144 | 144 | |
145 | - /** |
|
146 | - * Retrieves the document's `<body>` tag node. |
|
147 | - * |
|
148 | - * @return \DOMDocument |
|
149 | - */ |
|
145 | + /** |
|
146 | + * Retrieves the document's `<body>` tag node. |
|
147 | + * |
|
148 | + * @return \DOMDocument |
|
149 | + */ |
|
150 | 150 | public function getDOM() : \DOMDocument |
151 | 151 | { |
152 | 152 | return $this->dom; |
153 | 153 | } |
154 | 154 | |
155 | - /** |
|
156 | - * Retrieves all nodes from the HTML fragment (= child nodes |
|
157 | - * of the `<body>` element). |
|
158 | - * |
|
159 | - * @return \DOMNodeList |
|
160 | - */ |
|
155 | + /** |
|
156 | + * Retrieves all nodes from the HTML fragment (= child nodes |
|
157 | + * of the `<body>` element). |
|
158 | + * |
|
159 | + * @return \DOMNodeList |
|
160 | + */ |
|
161 | 161 | public function getFragmentNodes() : \DOMNodeList |
162 | 162 | { |
163 | 163 | return $this->bodyNode->childNodes; |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the LibXML HTML parsing errors collection, which |
|
168 | - * can be used to review any errors that occurred while loading |
|
169 | - * the HTML document. |
|
170 | - * |
|
171 | - * @return XMLHelper_DOMErrors |
|
172 | - */ |
|
166 | + /** |
|
167 | + * Retrieves the LibXML HTML parsing errors collection, which |
|
168 | + * can be used to review any errors that occurred while loading |
|
169 | + * the HTML document. |
|
170 | + * |
|
171 | + * @return XMLHelper_DOMErrors |
|
172 | + */ |
|
173 | 173 | public function getErrors() : XMLHelper_DOMErrors |
174 | 174 | { |
175 | 175 | return $this->errors; |
176 | 176 | } |
177 | 177 | |
178 | - /** |
|
179 | - * Returns a valid HTML string. |
|
180 | - * |
|
181 | - * @return string |
|
182 | - */ |
|
178 | + /** |
|
179 | + * Returns a valid HTML string. |
|
180 | + * |
|
181 | + * @return string |
|
182 | + */ |
|
183 | 183 | public function toHTML() : string |
184 | 184 | { |
185 | 185 | return $this->dom->saveHTML(); |
186 | 186 | } |
187 | 187 | |
188 | - /** |
|
189 | - * Returns a valid XML string. |
|
190 | - * |
|
191 | - * @return string |
|
192 | - */ |
|
188 | + /** |
|
189 | + * Returns a valid XML string. |
|
190 | + * |
|
191 | + * @return string |
|
192 | + */ |
|
193 | 193 | public function toXML() : string |
194 | 194 | { |
195 | 195 | return $this->dom->saveXML(); |
196 | 196 | } |
197 | 197 | |
198 | - /** |
|
199 | - * Converts the HTML fragment to valid XML (= all |
|
200 | - * child nodes of the `<body>` element). |
|
201 | - * |
|
202 | - * @return string |
|
203 | - */ |
|
198 | + /** |
|
199 | + * Converts the HTML fragment to valid XML (= all |
|
200 | + * child nodes of the `<body>` element). |
|
201 | + * |
|
202 | + * @return string |
|
203 | + */ |
|
204 | 204 | public function fragmentToXML() : string |
205 | 205 | { |
206 | 206 | $nodes = $this->getFragmentNodes(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | private static function checkFragment(string $fragment) : void |
109 | 109 | { |
110 | - if(!stristr($fragment, '<body') && !stristr($fragment, 'doctype')) |
|
110 | + if (!stristr($fragment, '<body') && !stristr($fragment, 'doctype')) |
|
111 | 111 | { |
112 | 112 | return; |
113 | 113 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | // capture all elements except the body tag itself |
209 | 209 | $xml = ''; |
210 | - foreach($nodes as $child) |
|
210 | + foreach ($nodes as $child) |
|
211 | 211 | { |
212 | 212 | $xml .= $this->dom->saveXML($child); |
213 | 213 | } |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | { |
24 | 24 | const SERIALIZE_SEPARATOR = '__SERSEP__'; |
25 | 25 | |
26 | - /** |
|
27 | - * @var XMLHelper_DOMErrors_Error[] |
|
28 | - */ |
|
26 | + /** |
|
27 | + * @var XMLHelper_DOMErrors_Error[] |
|
28 | + */ |
|
29 | 29 | private $errors; |
30 | 30 | |
31 | - /** |
|
32 | - * @param \LibXMLError[]|XMLHelper_DOMErrors_Error[] $libxmlErrors |
|
33 | - */ |
|
31 | + /** |
|
32 | + * @param \LibXMLError[]|XMLHelper_DOMErrors_Error[] $libxmlErrors |
|
33 | + */ |
|
34 | 34 | public function __construct(array $libxmlErrors) |
35 | 35 | { |
36 | 36 | foreach($libxmlErrors as $error) |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | return $this->errors; |
57 | 57 | } |
58 | 58 | |
59 | - /** |
|
60 | - * Retrieves all warnings, if any. |
|
61 | - * |
|
62 | - * @return XMLHelper_DOMErrors_Error[] |
|
63 | - */ |
|
59 | + /** |
|
60 | + * Retrieves all warnings, if any. |
|
61 | + * |
|
62 | + * @return XMLHelper_DOMErrors_Error[] |
|
63 | + */ |
|
64 | 64 | public function getWarnings() |
65 | 65 | { |
66 | 66 | return $this->getByLevel(LIBXML_ERR_WARNING); |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * Retrieves all errors by the specified libxml error level. |
|
112 | - * |
|
113 | - * @param int $level |
|
114 | - * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
115 | - */ |
|
110 | + /** |
|
111 | + * Retrieves all errors by the specified libxml error level. |
|
112 | + * |
|
113 | + * @param int $level |
|
114 | + * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
115 | + */ |
|
116 | 116 | public function getByLevel(int $level) |
117 | 117 | { |
118 | 118 | $result = array(); |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | return $result; |
129 | 129 | } |
130 | 130 | |
131 | - /** |
|
132 | - * Retrieves all errors by the specified libxml error code. |
|
133 | - * |
|
134 | - * @param int $code |
|
135 | - * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
136 | - */ |
|
131 | + /** |
|
132 | + * Retrieves all errors by the specified libxml error code. |
|
133 | + * |
|
134 | + * @param int $code |
|
135 | + * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
136 | + */ |
|
137 | 137 | public function getByCode(int $code) |
138 | 138 | { |
139 | 139 | $result = array(); |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | return $result; |
150 | 150 | } |
151 | 151 | |
152 | - /** |
|
153 | - * Checks whether there are errors matching the libxml error level. |
|
154 | - * |
|
155 | - * @param int $level |
|
156 | - * @return bool |
|
157 | - */ |
|
152 | + /** |
|
153 | + * Checks whether there are errors matching the libxml error level. |
|
154 | + * |
|
155 | + * @param int $level |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | 158 | public function hasErrorsByLevel(int $level) : bool |
159 | 159 | { |
160 | 160 | foreach($this->errors as $error) |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - /** |
|
172 | - * Checks whether there are any errors matching the libxml error code. |
|
173 | - * |
|
174 | - * @param int $code |
|
175 | - * @return bool |
|
176 | - */ |
|
171 | + /** |
|
172 | + * Checks whether there are any errors matching the libxml error code. |
|
173 | + * |
|
174 | + * @param int $code |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | 177 | public function hasErrorsByCode(int $code) : bool |
178 | 178 | { |
179 | 179 | foreach($this->errors as $error) |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | return $result; |
200 | 200 | } |
201 | 201 | |
202 | - /** |
|
203 | - * Serializes the errors collection, so it can be stored and |
|
204 | - * restored as needed, using the `fromSerialized()` method. |
|
205 | - * |
|
206 | - * @return string |
|
207 | - * @see XMLHelper_DOMErrors::fromSerialized() |
|
208 | - */ |
|
202 | + /** |
|
203 | + * Serializes the errors collection, so it can be stored and |
|
204 | + * restored as needed, using the `fromSerialized()` method. |
|
205 | + * |
|
206 | + * @return string |
|
207 | + * @see XMLHelper_DOMErrors::fromSerialized() |
|
208 | + */ |
|
209 | 209 | public function serialize() : string |
210 | 210 | { |
211 | 211 | $data = array(); |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | return implode(self::SERIALIZE_SEPARATOR, $data); |
219 | 219 | } |
220 | 220 | |
221 | - /** |
|
222 | - * Restores the errors collection from a previously serialized |
|
223 | - * collection, using `serialize()`. |
|
224 | - * |
|
225 | - * @param string $serialized |
|
226 | - * @return XMLHelper_DOMErrors |
|
227 | - * @see XMLHelper_DOMErrors::serialize() |
|
228 | - */ |
|
221 | + /** |
|
222 | + * Restores the errors collection from a previously serialized |
|
223 | + * collection, using `serialize()`. |
|
224 | + * |
|
225 | + * @param string $serialized |
|
226 | + * @return XMLHelper_DOMErrors |
|
227 | + * @see XMLHelper_DOMErrors::serialize() |
|
228 | + */ |
|
229 | 229 | public static function fromSerialized(string $serialized) : XMLHelper_DOMErrors |
230 | 230 | { |
231 | 231 | $parts = explode(self::SERIALIZE_SEPARATOR, $serialized); |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct(array $libxmlErrors) |
35 | 35 | { |
36 | - foreach($libxmlErrors as $error) |
|
36 | + foreach ($libxmlErrors as $error) |
|
37 | 37 | { |
38 | - if($error instanceof XMLHelper_DOMErrors_Error) |
|
38 | + if ($error instanceof XMLHelper_DOMErrors_Error) |
|
39 | 39 | { |
40 | 40 | $this->errors[] = $error; |
41 | 41 | } |
42 | - else if($error instanceof \LibXMLError) |
|
42 | + else if ($error instanceof \LibXMLError) |
|
43 | 43 | { |
44 | 44 | $this->errors[] = new XMLHelper_DOMErrors_Error($error); |
45 | 45 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | { |
118 | 118 | $result = array(); |
119 | 119 | |
120 | - foreach($this->errors as $error) |
|
120 | + foreach ($this->errors as $error) |
|
121 | 121 | { |
122 | - if($error->isLevel($level)) |
|
122 | + if ($error->isLevel($level)) |
|
123 | 123 | { |
124 | 124 | $result[] = $error; |
125 | 125 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | { |
139 | 139 | $result = array(); |
140 | 140 | |
141 | - foreach($this->errors as $error) |
|
141 | + foreach ($this->errors as $error) |
|
142 | 142 | { |
143 | - if($error->isCode($code)) |
|
143 | + if ($error->isCode($code)) |
|
144 | 144 | { |
145 | 145 | $result[] = $error; |
146 | 146 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function hasErrorsByLevel(int $level) : bool |
159 | 159 | { |
160 | - foreach($this->errors as $error) |
|
160 | + foreach ($this->errors as $error) |
|
161 | 161 | { |
162 | - if($error->isLevel($level)) |
|
162 | + if ($error->isLevel($level)) |
|
163 | 163 | { |
164 | 164 | return true; |
165 | 165 | } |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function hasErrorsByCode(int $code) : bool |
178 | 178 | { |
179 | - foreach($this->errors as $error) |
|
179 | + foreach ($this->errors as $error) |
|
180 | 180 | { |
181 | - if($error->isCode($code)) |
|
181 | + if ($error->isCode($code)) |
|
182 | 182 | { |
183 | 183 | return true; |
184 | 184 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | { |
192 | 192 | $result = array(); |
193 | 193 | |
194 | - foreach($this->errors as $error) |
|
194 | + foreach ($this->errors as $error) |
|
195 | 195 | { |
196 | 196 | $result[] = $error->toArray(); |
197 | 197 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | $data = array(); |
212 | 212 | |
213 | - foreach($this->errors as $error) |
|
213 | + foreach ($this->errors as $error) |
|
214 | 214 | { |
215 | 215 | $data[] = $error->serialize(); |
216 | 216 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $parts = explode(self::SERIALIZE_SEPARATOR, $serialized); |
232 | 232 | $list = array(); |
233 | 233 | |
234 | - foreach($parts as $part) |
|
234 | + foreach ($parts as $part) |
|
235 | 235 | { |
236 | 236 | $list[] = XMLHelper_DOMErrors_Error::fromSerialized($part); |
237 | 237 | } |
@@ -38,8 +38,7 @@ |
||
38 | 38 | if($error instanceof XMLHelper_DOMErrors_Error) |
39 | 39 | { |
40 | 40 | $this->errors[] = $error; |
41 | - } |
|
42 | - else if($error instanceof \LibXMLError) |
|
41 | + } else if($error instanceof \LibXMLError) |
|
43 | 42 | { |
44 | 43 | $this->errors[] = new XMLHelper_DOMErrors_Error($error); |
45 | 44 | } |
@@ -32,41 +32,41 @@ discard block |
||
32 | 32 | return new XMLHelper($dom); |
33 | 33 | } |
34 | 34 | |
35 | - /** |
|
36 | - * Creates a converter instance from an XML file. |
|
37 | - * @param string $xmlFile |
|
38 | - * @return \AppUtils\XMLHelper_Converter |
|
39 | - */ |
|
35 | + /** |
|
36 | + * Creates a converter instance from an XML file. |
|
37 | + * @param string $xmlFile |
|
38 | + * @return \AppUtils\XMLHelper_Converter |
|
39 | + */ |
|
40 | 40 | public static function convertFile(string $xmlFile) |
41 | 41 | { |
42 | 42 | return XMLHelper_Converter::fromFile($xmlFile); |
43 | 43 | } |
44 | 44 | |
45 | - /** |
|
46 | - * Creates a converter from an XML string. |
|
47 | - * @param string $xmlString |
|
48 | - * @return \AppUtils\XMLHelper_Converter |
|
49 | - */ |
|
45 | + /** |
|
46 | + * Creates a converter from an XML string. |
|
47 | + * @param string $xmlString |
|
48 | + * @return \AppUtils\XMLHelper_Converter |
|
49 | + */ |
|
50 | 50 | public static function convertString(string $xmlString) |
51 | 51 | { |
52 | 52 | return XMLHelper_Converter::fromString($xmlString); |
53 | 53 | } |
54 | 54 | |
55 | - /** |
|
56 | - * Creates a converter from a SimpleXMLElement instance. |
|
57 | - * @param \SimpleXMLElement $element |
|
58 | - * @return \AppUtils\XMLHelper_Converter |
|
59 | - */ |
|
55 | + /** |
|
56 | + * Creates a converter from a SimpleXMLElement instance. |
|
57 | + * @param \SimpleXMLElement $element |
|
58 | + * @return \AppUtils\XMLHelper_Converter |
|
59 | + */ |
|
60 | 60 | public static function convertElement(\SimpleXMLElement $element) |
61 | 61 | { |
62 | 62 | return XMLHelper_Converter::fromElement($element); |
63 | 63 | } |
64 | 64 | |
65 | - /** |
|
66 | - * Creates a converter from a DOMElement instance. |
|
67 | - * @param \DOMElement $element |
|
68 | - * @return \AppUtils\XMLHelper_Converter |
|
69 | - */ |
|
65 | + /** |
|
66 | + * Creates a converter from a DOMElement instance. |
|
67 | + * @param \DOMElement $element |
|
68 | + * @return \AppUtils\XMLHelper_Converter |
|
69 | + */ |
|
70 | 70 | public static function convertDOMElement(\DOMElement $element) |
71 | 71 | { |
72 | 72 | return XMLHelper_Converter::fromDOMElement($element); |
@@ -435,31 +435,31 @@ discard block |
||
435 | 435 | return $this->dom->saveXML(); |
436 | 436 | } |
437 | 437 | |
438 | - /** |
|
439 | - * Creates a new SimpleXML helper instance: this |
|
440 | - * object is useful to work with loading XML strings |
|
441 | - * and files with easy access to any errors that |
|
442 | - * may occurr, since the simplexml functions can be |
|
443 | - * somewhat cryptic. |
|
444 | - * |
|
445 | - * @return XMLHelper_SimpleXML |
|
446 | - */ |
|
438 | + /** |
|
439 | + * Creates a new SimpleXML helper instance: this |
|
440 | + * object is useful to work with loading XML strings |
|
441 | + * and files with easy access to any errors that |
|
442 | + * may occurr, since the simplexml functions can be |
|
443 | + * somewhat cryptic. |
|
444 | + * |
|
445 | + * @return XMLHelper_SimpleXML |
|
446 | + */ |
|
447 | 447 | public static function createSimplexml() |
448 | 448 | { |
449 | 449 | return new XMLHelper_SimpleXML(); |
450 | 450 | } |
451 | 451 | |
452 | - /** |
|
453 | - * Converts a string to valid XML: can be a text only string |
|
454 | - * or an HTML string. Returns valid XML code. |
|
455 | - * |
|
456 | - * NOTE: The string may contain custom tags, which are |
|
457 | - * preserved. |
|
458 | - * |
|
459 | - * @param string $string |
|
460 | - * @throws XMLHelper_Exception |
|
461 | - * @return string |
|
462 | - */ |
|
452 | + /** |
|
453 | + * Converts a string to valid XML: can be a text only string |
|
454 | + * or an HTML string. Returns valid XML code. |
|
455 | + * |
|
456 | + * NOTE: The string may contain custom tags, which are |
|
457 | + * preserved. |
|
458 | + * |
|
459 | + * @param string $string |
|
460 | + * @throws XMLHelper_Exception |
|
461 | + * @return string |
|
462 | + */ |
|
463 | 463 | public static function string2xml(string $string) : string |
464 | 464 | { |
465 | 465 | return XMLHelper_HTMLLoader::loadFragment($string)->fragmentToXML(); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function addAttribute($parent, string $name, $value) |
107 | 107 | { |
108 | - if(!$parent instanceof \DOMNode) { |
|
108 | + if (!$parent instanceof \DOMNode) { |
|
109 | 109 | throw new XMLHelper_Exception( |
110 | 110 | 'The specified parent node is not a node instance.', |
111 | 111 | sprintf('Tried adding attribute [%s].', $name), |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | |
228 | 228 | if (!empty($text)) { |
229 | 229 | $fragment = $this->dom->createDocumentFragment(); |
230 | - if(!@$fragment->appendXML($text)) { |
|
230 | + if (!@$fragment->appendXML($text)) { |
|
231 | 231 | throw new XMLHelper_Exception( |
232 | 232 | 'Cannot append XML fragment', |
233 | 233 | sprintf( |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @param array $attributes |
270 | 270 | * @return \DOMNode |
271 | 271 | */ |
272 | - public function createRoot($name, $attributes=array()) |
|
272 | + public function createRoot($name, $attributes = array()) |
|
273 | 273 | { |
274 | 274 | $root = $this->dom->appendChild($this->dom->createElement($name)); |
275 | 275 | $this->addAttributes($root, $attributes); |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | $string = str_replace('<', 'LT_ESCAPE', $string); |
291 | 291 | $string = str_replace('>', 'GT_ESCAPE', $string); |
292 | 292 | |
293 | - $string = str_replace(' ',' ', $string); |
|
294 | - $string = str_replace('&','&', $string); |
|
293 | + $string = str_replace(' ', ' ', $string); |
|
294 | + $string = str_replace('&', '&', $string); |
|
295 | 295 | |
296 | 296 | return $string; |
297 | 297 | } |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public static function downloadXML($xml, $filename = 'download.xml') |
308 | 308 | { |
309 | - if(!headers_sent() && !self::$simulation) { |
|
310 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
309 | + if (!headers_sent() && !self::$simulation) { |
|
310 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | echo $xml; |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public static function displayXML($xml) |
324 | 324 | { |
325 | - if(!headers_sent() && !self::$simulation) { |
|
325 | + if (!headers_sent() && !self::$simulation) { |
|
326 | 326 | header('Content-Type:text/xml; charset=utf-8'); |
327 | 327 | } |
328 | 328 | |
329 | - if(self::$simulation) { |
|
329 | + if (self::$simulation) { |
|
330 | 330 | $xml = '<pre>'.htmlspecialchars($xml).'</pre>'; |
331 | 331 | } |
332 | 332 | |
@@ -344,10 +344,10 @@ discard block |
||
344 | 344 | * @param string[] $customInfo Associative array with name => value pairs for custom tags to add to the output xml |
345 | 345 | * @see buildErrorXML() |
346 | 346 | */ |
347 | - public static function displayErrorXML($code, $message, $title, $customInfo=array()) |
|
347 | + public static function displayErrorXML($code, $message, $title, $customInfo = array()) |
|
348 | 348 | { |
349 | - if(!headers_sent() && !self::$simulation) { |
|
350 | - header('HTTP/1.1 400 Bad Request: ' . $title, true, 400); |
|
349 | + if (!headers_sent() && !self::$simulation) { |
|
350 | + header('HTTP/1.1 400 Bad Request: '.$title, true, 400); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | self::displayXML(self::buildErrorXML($code, $message, $title, $customInfo)); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | |
356 | 356 | protected static $simulation = false; |
357 | 357 | |
358 | - public static function setSimulation($simulate=true) |
|
358 | + public static function setSimulation($simulate = true) |
|
359 | 359 | { |
360 | 360 | self::$simulation = $simulate; |
361 | 361 | } |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @param string $title |
404 | 404 | * @return string |
405 | 405 | */ |
406 | - public static function buildErrorXML($code, $message, $title, $customInfo=array()) |
|
406 | + public static function buildErrorXML($code, $message, $title, $customInfo = array()) |
|
407 | 407 | { |
408 | 408 | $xml = new \DOMDocument('1.0', 'UTF-8'); |
409 | 409 | $xml->formatOutput = true; |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | $helper->addTextTag($root, 'title', $title); |
418 | 418 | $helper->addTextTag($root, 'request_uri', $_SERVER['REQUEST_URI']); |
419 | 419 | |
420 | - foreach($customInfo as $name => $value) { |
|
420 | + foreach ($customInfo as $name => $value) { |
|
421 | 421 | $helper->addTextTag($root, $name, $value); |
422 | 422 | } |
423 | 423 |
@@ -14,9 +14,9 @@ |
||
14 | 14 | * @see http://www.xmlsoft.org/html/libxml-xmlerror.html |
15 | 15 | */ |
16 | 16 | |
17 | - /** |
|
18 | - * @var string $list |
|
19 | - */ |
|
17 | + /** |
|
18 | + * @var string $list |
|
19 | + */ |
|
20 | 20 | $list = file_get_contents('libxmlerrors.txt'); |
21 | 21 | $outputFile = 'LibXML.php'; |
22 | 22 | $lines = explode("\n", $list); |
@@ -22,7 +22,7 @@ |
||
22 | 22 | $lines = explode("\n", $list); |
23 | 23 | $reverseArray = array(); |
24 | 24 | |
25 | - foreach($lines as $line) |
|
25 | + foreach ($lines as $line) |
|
26 | 26 | { |
27 | 27 | $parts = explode('=', $line); |
28 | 28 | $name = trim(str_replace('XML_ERR_', '', $parts[0])); |