@@ -19,66 +19,66 @@ |
||
19 | 19 | */ |
20 | 20 | class Base implements Xml\Element |
21 | 21 | { |
22 | - /** |
|
23 | - * PHP value to serialize. |
|
24 | - * |
|
25 | - * @var mixed |
|
26 | - */ |
|
27 | - protected $value; |
|
22 | + /** |
|
23 | + * PHP value to serialize. |
|
24 | + * |
|
25 | + * @var mixed |
|
26 | + */ |
|
27 | + protected $value; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - */ |
|
32 | - public function __construct($value = null) |
|
33 | - { |
|
34 | - $this->value = $value; |
|
35 | - } |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + */ |
|
32 | + public function __construct($value = null) |
|
33 | + { |
|
34 | + $this->value = $value; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * The xmlSerialize method is called during xml writing. |
|
39 | - * |
|
40 | - * Use the $writer argument to write its own xml serialization. |
|
41 | - * |
|
42 | - * An important note: do _not_ create a parent element. Any element |
|
43 | - * implementing XmlSerializable should only ever write what's considered |
|
44 | - * its 'inner xml'. |
|
45 | - * |
|
46 | - * The parent of the current element is responsible for writing a |
|
47 | - * containing element. |
|
48 | - * |
|
49 | - * This allows serializers to be re-used for different element names. |
|
50 | - * |
|
51 | - * If you are opening new elements, you must also close them again. |
|
52 | - */ |
|
53 | - public function xmlSerialize(Xml\Writer $writer) |
|
54 | - { |
|
55 | - $writer->write($this->value); |
|
56 | - } |
|
37 | + /** |
|
38 | + * The xmlSerialize method is called during xml writing. |
|
39 | + * |
|
40 | + * Use the $writer argument to write its own xml serialization. |
|
41 | + * |
|
42 | + * An important note: do _not_ create a parent element. Any element |
|
43 | + * implementing XmlSerializable should only ever write what's considered |
|
44 | + * its 'inner xml'. |
|
45 | + * |
|
46 | + * The parent of the current element is responsible for writing a |
|
47 | + * containing element. |
|
48 | + * |
|
49 | + * This allows serializers to be re-used for different element names. |
|
50 | + * |
|
51 | + * If you are opening new elements, you must also close them again. |
|
52 | + */ |
|
53 | + public function xmlSerialize(Xml\Writer $writer) |
|
54 | + { |
|
55 | + $writer->write($this->value); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * The deserialize method is called during xml parsing. |
|
60 | - * |
|
61 | - * This method is called statically, this is because in theory this method |
|
62 | - * may be used as a type of constructor, or factory method. |
|
63 | - * |
|
64 | - * Often you want to return an instance of the current class, but you are |
|
65 | - * free to return other data as well. |
|
66 | - * |
|
67 | - * Important note 2: You are responsible for advancing the reader to the |
|
68 | - * next element. Not doing anything will result in a never-ending loop. |
|
69 | - * |
|
70 | - * If you just want to skip parsing for this element altogether, you can |
|
71 | - * just call $reader->next(); |
|
72 | - * |
|
73 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
74 | - * the next element. |
|
75 | - * |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public static function xmlDeserialize(Xml\Reader $reader) |
|
79 | - { |
|
80 | - $subTree = $reader->parseInnerTree(); |
|
58 | + /** |
|
59 | + * The deserialize method is called during xml parsing. |
|
60 | + * |
|
61 | + * This method is called statically, this is because in theory this method |
|
62 | + * may be used as a type of constructor, or factory method. |
|
63 | + * |
|
64 | + * Often you want to return an instance of the current class, but you are |
|
65 | + * free to return other data as well. |
|
66 | + * |
|
67 | + * Important note 2: You are responsible for advancing the reader to the |
|
68 | + * next element. Not doing anything will result in a never-ending loop. |
|
69 | + * |
|
70 | + * If you just want to skip parsing for this element altogether, you can |
|
71 | + * just call $reader->next(); |
|
72 | + * |
|
73 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
74 | + * the next element. |
|
75 | + * |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public static function xmlDeserialize(Xml\Reader $reader) |
|
79 | + { |
|
80 | + $subTree = $reader->parseInnerTree(); |
|
81 | 81 | |
82 | - return $subTree; |
|
83 | - } |
|
82 | + return $subTree; |
|
83 | + } |
|
84 | 84 | } |
@@ -18,32 +18,32 @@ |
||
18 | 18 | */ |
19 | 19 | class LibXMLException extends ParseException |
20 | 20 | { |
21 | - /** |
|
22 | - * The error list. |
|
23 | - * |
|
24 | - * @var \LibXMLError[] |
|
25 | - */ |
|
26 | - protected $errors; |
|
21 | + /** |
|
22 | + * The error list. |
|
23 | + * |
|
24 | + * @var \LibXMLError[] |
|
25 | + */ |
|
26 | + protected $errors; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Creates the exception. |
|
30 | - * |
|
31 | - * You should pass a list of LibXMLError objects in its constructor. |
|
32 | - * |
|
33 | - * @param LibXMLError[] $errors |
|
34 | - * @param Throwable $previousException |
|
35 | - */ |
|
36 | - public function __construct(array $errors, int $code = 0, Throwable $previousException = null) |
|
37 | - { |
|
38 | - $this->errors = $errors; |
|
39 | - parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException); |
|
40 | - } |
|
28 | + /** |
|
29 | + * Creates the exception. |
|
30 | + * |
|
31 | + * You should pass a list of LibXMLError objects in its constructor. |
|
32 | + * |
|
33 | + * @param LibXMLError[] $errors |
|
34 | + * @param Throwable $previousException |
|
35 | + */ |
|
36 | + public function __construct(array $errors, int $code = 0, Throwable $previousException = null) |
|
37 | + { |
|
38 | + $this->errors = $errors; |
|
39 | + parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns the LibXML errors. |
|
44 | - */ |
|
45 | - public function getErrors(): array |
|
46 | - { |
|
47 | - return $this->errors; |
|
48 | - } |
|
42 | + /** |
|
43 | + * Returns the LibXML errors. |
|
44 | + */ |
|
45 | + public function getErrors(): array |
|
46 | + { |
|
47 | + return $this->errors; |
|
48 | + } |
|
49 | 49 | } |
@@ -32,226 +32,226 @@ |
||
32 | 32 | */ |
33 | 33 | class Writer extends XMLWriter |
34 | 34 | { |
35 | - use ContextStackTrait; |
|
35 | + use ContextStackTrait; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Any namespace that the writer is asked to write, will be added here. |
|
39 | - * |
|
40 | - * Any of these elements will get a new namespace definition *every single |
|
41 | - * time* they are used, but this array allows the writer to make sure that |
|
42 | - * the prefixes are consistent anyway. |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $adhocNamespaces = []; |
|
37 | + /** |
|
38 | + * Any namespace that the writer is asked to write, will be added here. |
|
39 | + * |
|
40 | + * Any of these elements will get a new namespace definition *every single |
|
41 | + * time* they are used, but this array allows the writer to make sure that |
|
42 | + * the prefixes are consistent anyway. |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $adhocNamespaces = []; |
|
47 | 47 | |
48 | - /** |
|
49 | - * When the first element is written, this flag is set to true. |
|
50 | - * |
|
51 | - * This ensures that the namespaces in the namespaces map are only written |
|
52 | - * once. |
|
53 | - * |
|
54 | - * @var bool |
|
55 | - */ |
|
56 | - protected $namespacesWritten = false; |
|
48 | + /** |
|
49 | + * When the first element is written, this flag is set to true. |
|
50 | + * |
|
51 | + * This ensures that the namespaces in the namespaces map are only written |
|
52 | + * once. |
|
53 | + * |
|
54 | + * @var bool |
|
55 | + */ |
|
56 | + protected $namespacesWritten = false; |
|
57 | 57 | |
58 | - /** |
|
59 | - * Writes a value to the output stream. |
|
60 | - * |
|
61 | - * The following values are supported: |
|
62 | - * 1. Scalar values will be written as-is, as text. |
|
63 | - * 2. Null values will be skipped (resulting in a short xml tag). |
|
64 | - * 3. If a value is an instance of an Element class, writing will be |
|
65 | - * delegated to the object. |
|
66 | - * 4. If a value is an array, two formats are supported. |
|
67 | - * |
|
68 | - * Array format 1: |
|
69 | - * [ |
|
70 | - * "{namespace}name1" => "..", |
|
71 | - * "{namespace}name2" => "..", |
|
72 | - * ] |
|
73 | - * |
|
74 | - * One element will be created for each key in this array. The values of |
|
75 | - * this array support any format this method supports (this method is |
|
76 | - * called recursively). |
|
77 | - * |
|
78 | - * Array format 2: |
|
79 | - * |
|
80 | - * [ |
|
81 | - * [ |
|
82 | - * "name" => "{namespace}name1" |
|
83 | - * "value" => "..", |
|
84 | - * "attributes" => [ |
|
85 | - * "attr" => "attribute value", |
|
86 | - * ] |
|
87 | - * ], |
|
88 | - * [ |
|
89 | - * "name" => "{namespace}name1" |
|
90 | - * "value" => "..", |
|
91 | - * "attributes" => [ |
|
92 | - * "attr" => "attribute value", |
|
93 | - * ] |
|
94 | - * ] |
|
95 | - * ] |
|
96 | - * |
|
97 | - * @param mixed $value |
|
98 | - */ |
|
99 | - public function write($value) |
|
100 | - { |
|
101 | - Serializer\standardSerializer($this, $value); |
|
102 | - } |
|
58 | + /** |
|
59 | + * Writes a value to the output stream. |
|
60 | + * |
|
61 | + * The following values are supported: |
|
62 | + * 1. Scalar values will be written as-is, as text. |
|
63 | + * 2. Null values will be skipped (resulting in a short xml tag). |
|
64 | + * 3. If a value is an instance of an Element class, writing will be |
|
65 | + * delegated to the object. |
|
66 | + * 4. If a value is an array, two formats are supported. |
|
67 | + * |
|
68 | + * Array format 1: |
|
69 | + * [ |
|
70 | + * "{namespace}name1" => "..", |
|
71 | + * "{namespace}name2" => "..", |
|
72 | + * ] |
|
73 | + * |
|
74 | + * One element will be created for each key in this array. The values of |
|
75 | + * this array support any format this method supports (this method is |
|
76 | + * called recursively). |
|
77 | + * |
|
78 | + * Array format 2: |
|
79 | + * |
|
80 | + * [ |
|
81 | + * [ |
|
82 | + * "name" => "{namespace}name1" |
|
83 | + * "value" => "..", |
|
84 | + * "attributes" => [ |
|
85 | + * "attr" => "attribute value", |
|
86 | + * ] |
|
87 | + * ], |
|
88 | + * [ |
|
89 | + * "name" => "{namespace}name1" |
|
90 | + * "value" => "..", |
|
91 | + * "attributes" => [ |
|
92 | + * "attr" => "attribute value", |
|
93 | + * ] |
|
94 | + * ] |
|
95 | + * ] |
|
96 | + * |
|
97 | + * @param mixed $value |
|
98 | + */ |
|
99 | + public function write($value) |
|
100 | + { |
|
101 | + Serializer\standardSerializer($this, $value); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Opens a new element. |
|
106 | - * |
|
107 | - * You can either just use a local elementname, or you can use clark- |
|
108 | - * notation to start a new element. |
|
109 | - * |
|
110 | - * Example: |
|
111 | - * |
|
112 | - * $writer->startElement('{http://www.w3.org/2005/Atom}entry'); |
|
113 | - * |
|
114 | - * Would result in something like: |
|
115 | - * |
|
116 | - * <entry xmlns="http://w3.org/2005/Atom"> |
|
117 | - * |
|
118 | - * Note: this function doesn't have the string typehint, because PHP's |
|
119 | - * XMLWriter::startElement doesn't either. |
|
120 | - * |
|
121 | - * @param string $name |
|
122 | - */ |
|
123 | - public function startElement($name): bool |
|
124 | - { |
|
125 | - if ('{' === $name[0]) { |
|
126 | - list($namespace, $localName) = |
|
127 | - Service::parseClarkNotation($name); |
|
104 | + /** |
|
105 | + * Opens a new element. |
|
106 | + * |
|
107 | + * You can either just use a local elementname, or you can use clark- |
|
108 | + * notation to start a new element. |
|
109 | + * |
|
110 | + * Example: |
|
111 | + * |
|
112 | + * $writer->startElement('{http://www.w3.org/2005/Atom}entry'); |
|
113 | + * |
|
114 | + * Would result in something like: |
|
115 | + * |
|
116 | + * <entry xmlns="http://w3.org/2005/Atom"> |
|
117 | + * |
|
118 | + * Note: this function doesn't have the string typehint, because PHP's |
|
119 | + * XMLWriter::startElement doesn't either. |
|
120 | + * |
|
121 | + * @param string $name |
|
122 | + */ |
|
123 | + public function startElement($name): bool |
|
124 | + { |
|
125 | + if ('{' === $name[0]) { |
|
126 | + list($namespace, $localName) = |
|
127 | + Service::parseClarkNotation($name); |
|
128 | 128 | |
129 | - if (array_key_exists($namespace, $this->namespaceMap)) { |
|
130 | - $result = $this->startElementNS( |
|
131 | - '' === $this->namespaceMap[$namespace] ? null : $this->namespaceMap[$namespace], |
|
132 | - $localName, |
|
133 | - null |
|
134 | - ); |
|
135 | - } else { |
|
136 | - // An empty namespace means it's the global namespace. This is |
|
137 | - // allowed, but it mustn't get a prefix. |
|
138 | - if ('' === $namespace || null === $namespace) { |
|
139 | - $result = $this->startElement($localName); |
|
140 | - $this->writeAttribute('xmlns', ''); |
|
141 | - } else { |
|
142 | - if (!isset($this->adhocNamespaces[$namespace])) { |
|
143 | - $this->adhocNamespaces[$namespace] = 'x'.(count($this->adhocNamespaces) + 1); |
|
144 | - } |
|
145 | - $result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace); |
|
146 | - } |
|
147 | - } |
|
148 | - } else { |
|
149 | - $result = parent::startElement($name); |
|
150 | - } |
|
129 | + if (array_key_exists($namespace, $this->namespaceMap)) { |
|
130 | + $result = $this->startElementNS( |
|
131 | + '' === $this->namespaceMap[$namespace] ? null : $this->namespaceMap[$namespace], |
|
132 | + $localName, |
|
133 | + null |
|
134 | + ); |
|
135 | + } else { |
|
136 | + // An empty namespace means it's the global namespace. This is |
|
137 | + // allowed, but it mustn't get a prefix. |
|
138 | + if ('' === $namespace || null === $namespace) { |
|
139 | + $result = $this->startElement($localName); |
|
140 | + $this->writeAttribute('xmlns', ''); |
|
141 | + } else { |
|
142 | + if (!isset($this->adhocNamespaces[$namespace])) { |
|
143 | + $this->adhocNamespaces[$namespace] = 'x'.(count($this->adhocNamespaces) + 1); |
|
144 | + } |
|
145 | + $result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace); |
|
146 | + } |
|
147 | + } |
|
148 | + } else { |
|
149 | + $result = parent::startElement($name); |
|
150 | + } |
|
151 | 151 | |
152 | - if (!$this->namespacesWritten) { |
|
153 | - foreach ($this->namespaceMap as $namespace => $prefix) { |
|
154 | - $this->writeAttribute(($prefix ? 'xmlns:'.$prefix : 'xmlns'), $namespace); |
|
155 | - } |
|
156 | - $this->namespacesWritten = true; |
|
157 | - } |
|
152 | + if (!$this->namespacesWritten) { |
|
153 | + foreach ($this->namespaceMap as $namespace => $prefix) { |
|
154 | + $this->writeAttribute(($prefix ? 'xmlns:'.$prefix : 'xmlns'), $namespace); |
|
155 | + } |
|
156 | + $this->namespacesWritten = true; |
|
157 | + } |
|
158 | 158 | |
159 | - return $result; |
|
160 | - } |
|
159 | + return $result; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Write a full element tag and it's contents. |
|
164 | - * |
|
165 | - * This method automatically closes the element as well. |
|
166 | - * |
|
167 | - * The element name may be specified in clark-notation. |
|
168 | - * |
|
169 | - * Examples: |
|
170 | - * |
|
171 | - * $writer->writeElement('{http://www.w3.org/2005/Atom}author',null); |
|
172 | - * becomes: |
|
173 | - * <author xmlns="http://www.w3.org/2005" /> |
|
174 | - * |
|
175 | - * $writer->writeElement('{http://www.w3.org/2005/Atom}author', [ |
|
176 | - * '{http://www.w3.org/2005/Atom}name' => 'Evert Pot', |
|
177 | - * ]); |
|
178 | - * becomes: |
|
179 | - * <author xmlns="http://www.w3.org/2005" /><name>Evert Pot</name></author> |
|
180 | - * |
|
181 | - * Note: this function doesn't have the string typehint, because PHP's |
|
182 | - * XMLWriter::startElement doesn't either. |
|
183 | - * |
|
184 | - * @param array|string|object|null $content |
|
185 | - */ |
|
186 | - public function writeElement($name, $content = null): bool |
|
187 | - { |
|
188 | - $this->startElement($name); |
|
189 | - if (!is_null($content)) { |
|
190 | - $this->write($content); |
|
191 | - } |
|
192 | - $this->endElement(); |
|
162 | + /** |
|
163 | + * Write a full element tag and it's contents. |
|
164 | + * |
|
165 | + * This method automatically closes the element as well. |
|
166 | + * |
|
167 | + * The element name may be specified in clark-notation. |
|
168 | + * |
|
169 | + * Examples: |
|
170 | + * |
|
171 | + * $writer->writeElement('{http://www.w3.org/2005/Atom}author',null); |
|
172 | + * becomes: |
|
173 | + * <author xmlns="http://www.w3.org/2005" /> |
|
174 | + * |
|
175 | + * $writer->writeElement('{http://www.w3.org/2005/Atom}author', [ |
|
176 | + * '{http://www.w3.org/2005/Atom}name' => 'Evert Pot', |
|
177 | + * ]); |
|
178 | + * becomes: |
|
179 | + * <author xmlns="http://www.w3.org/2005" /><name>Evert Pot</name></author> |
|
180 | + * |
|
181 | + * Note: this function doesn't have the string typehint, because PHP's |
|
182 | + * XMLWriter::startElement doesn't either. |
|
183 | + * |
|
184 | + * @param array|string|object|null $content |
|
185 | + */ |
|
186 | + public function writeElement($name, $content = null): bool |
|
187 | + { |
|
188 | + $this->startElement($name); |
|
189 | + if (!is_null($content)) { |
|
190 | + $this->write($content); |
|
191 | + } |
|
192 | + $this->endElement(); |
|
193 | 193 | |
194 | - return true; |
|
195 | - } |
|
194 | + return true; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Writes a list of attributes. |
|
199 | - * |
|
200 | - * Attributes are specified as a key->value array. |
|
201 | - * |
|
202 | - * The key is an attribute name. If the key is a 'localName', the current |
|
203 | - * xml namespace is assumed. If it's a 'clark notation key', this namespace |
|
204 | - * will be used instead. |
|
205 | - */ |
|
206 | - public function writeAttributes(array $attributes) |
|
207 | - { |
|
208 | - foreach ($attributes as $name => $value) { |
|
209 | - $this->writeAttribute($name, $value); |
|
210 | - } |
|
211 | - } |
|
197 | + /** |
|
198 | + * Writes a list of attributes. |
|
199 | + * |
|
200 | + * Attributes are specified as a key->value array. |
|
201 | + * |
|
202 | + * The key is an attribute name. If the key is a 'localName', the current |
|
203 | + * xml namespace is assumed. If it's a 'clark notation key', this namespace |
|
204 | + * will be used instead. |
|
205 | + */ |
|
206 | + public function writeAttributes(array $attributes) |
|
207 | + { |
|
208 | + foreach ($attributes as $name => $value) { |
|
209 | + $this->writeAttribute($name, $value); |
|
210 | + } |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Writes a new attribute. |
|
215 | - * |
|
216 | - * The name may be specified in clark-notation. |
|
217 | - * |
|
218 | - * Returns true when successful. |
|
219 | - * |
|
220 | - * Note: this function doesn't have typehints, because for some reason |
|
221 | - * PHP's XMLWriter::writeAttribute doesn't either. |
|
222 | - * |
|
223 | - * @param string $name |
|
224 | - * @param string $value |
|
225 | - */ |
|
226 | - public function writeAttribute($name, $value): bool |
|
227 | - { |
|
228 | - if ('{' !== $name[0]) { |
|
229 | - return parent::writeAttribute($name, $value); |
|
230 | - } |
|
213 | + /** |
|
214 | + * Writes a new attribute. |
|
215 | + * |
|
216 | + * The name may be specified in clark-notation. |
|
217 | + * |
|
218 | + * Returns true when successful. |
|
219 | + * |
|
220 | + * Note: this function doesn't have typehints, because for some reason |
|
221 | + * PHP's XMLWriter::writeAttribute doesn't either. |
|
222 | + * |
|
223 | + * @param string $name |
|
224 | + * @param string $value |
|
225 | + */ |
|
226 | + public function writeAttribute($name, $value): bool |
|
227 | + { |
|
228 | + if ('{' !== $name[0]) { |
|
229 | + return parent::writeAttribute($name, $value); |
|
230 | + } |
|
231 | 231 | |
232 | - list( |
|
233 | - $namespace, |
|
234 | - $localName |
|
235 | - ) = Service::parseClarkNotation($name); |
|
232 | + list( |
|
233 | + $namespace, |
|
234 | + $localName |
|
235 | + ) = Service::parseClarkNotation($name); |
|
236 | 236 | |
237 | - if (array_key_exists($namespace, $this->namespaceMap)) { |
|
238 | - // It's an attribute with a namespace we know |
|
239 | - return $this->writeAttribute( |
|
240 | - $this->namespaceMap[$namespace].':'.$localName, |
|
241 | - $value |
|
242 | - ); |
|
243 | - } |
|
237 | + if (array_key_exists($namespace, $this->namespaceMap)) { |
|
238 | + // It's an attribute with a namespace we know |
|
239 | + return $this->writeAttribute( |
|
240 | + $this->namespaceMap[$namespace].':'.$localName, |
|
241 | + $value |
|
242 | + ); |
|
243 | + } |
|
244 | 244 | |
245 | - // We don't know the namespace, we must add it in-line |
|
246 | - if (!isset($this->adhocNamespaces[$namespace])) { |
|
247 | - $this->adhocNamespaces[$namespace] = 'x'.(count($this->adhocNamespaces) + 1); |
|
248 | - } |
|
245 | + // We don't know the namespace, we must add it in-line |
|
246 | + if (!isset($this->adhocNamespaces[$namespace])) { |
|
247 | + $this->adhocNamespaces[$namespace] = 'x'.(count($this->adhocNamespaces) + 1); |
|
248 | + } |
|
249 | 249 | |
250 | - return $this->writeAttributeNS( |
|
251 | - $this->adhocNamespaces[$namespace], |
|
252 | - $localName, |
|
253 | - $namespace, |
|
254 | - $value |
|
255 | - ); |
|
256 | - } |
|
250 | + return $this->writeAttributeNS( |
|
251 | + $this->adhocNamespaces[$namespace], |
|
252 | + $localName, |
|
253 | + $namespace, |
|
254 | + $value |
|
255 | + ); |
|
256 | + } |
|
257 | 257 | } |
@@ -21,287 +21,287 @@ |
||
21 | 21 | */ |
22 | 22 | class Reader extends XMLReader |
23 | 23 | { |
24 | - use ContextStackTrait; |
|
25 | - |
|
26 | - /** |
|
27 | - * Returns the current nodename in clark-notation. |
|
28 | - * |
|
29 | - * For example: "{http://www.w3.org/2005/Atom}feed". |
|
30 | - * Or if no namespace is defined: "{}feed". |
|
31 | - * |
|
32 | - * This method returns null if we're not currently on an element. |
|
33 | - * |
|
34 | - * @return string|null |
|
35 | - */ |
|
36 | - public function getClark() |
|
37 | - { |
|
38 | - if (!$this->localName) { |
|
39 | - return null; |
|
40 | - } |
|
41 | - |
|
42 | - return '{'.$this->namespaceURI.'}'.$this->localName; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Reads the entire document. |
|
47 | - * |
|
48 | - * This function returns an array with the following three elements: |
|
49 | - * * name - The root element name. |
|
50 | - * * value - The value for the root element. |
|
51 | - * * attributes - An array of attributes. |
|
52 | - * |
|
53 | - * This function will also disable the standard libxml error handler (which |
|
54 | - * usually just results in PHP errors), and throw exceptions instead. |
|
55 | - */ |
|
56 | - public function parse(): array |
|
57 | - { |
|
58 | - $previousEntityState = null; |
|
59 | - $shouldCallLibxmlDisableEntityLoader = (\LIBXML_VERSION < 20900); |
|
60 | - if ($shouldCallLibxmlDisableEntityLoader) { |
|
61 | - $previousEntityState = libxml_disable_entity_loader(true); |
|
62 | - } |
|
63 | - $previousSetting = libxml_use_internal_errors(true); |
|
64 | - |
|
65 | - try { |
|
66 | - while (self::ELEMENT !== $this->nodeType) { |
|
67 | - if (!$this->read()) { |
|
68 | - $errors = libxml_get_errors(); |
|
69 | - libxml_clear_errors(); |
|
70 | - if ($errors) { |
|
71 | - throw new LibXMLException($errors); |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - $result = $this->parseCurrentElement(); |
|
76 | - |
|
77 | - // last line of defense in case errors did occur above |
|
78 | - $errors = libxml_get_errors(); |
|
79 | - libxml_clear_errors(); |
|
80 | - if ($errors) { |
|
81 | - throw new LibXMLException($errors); |
|
82 | - } |
|
83 | - } finally { |
|
84 | - libxml_use_internal_errors($previousSetting); |
|
85 | - if ($shouldCallLibxmlDisableEntityLoader) { |
|
86 | - libxml_disable_entity_loader($previousEntityState); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - return $result; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * parseGetElements parses everything in the current sub-tree, |
|
95 | - * and returns an array of elements. |
|
96 | - * |
|
97 | - * Each element has a 'name', 'value' and 'attributes' key. |
|
98 | - * |
|
99 | - * If the element didn't contain sub-elements, an empty array is always |
|
100 | - * returned. If there was any text inside the element, it will be |
|
101 | - * discarded. |
|
102 | - * |
|
103 | - * If the $elementMap argument is specified, the existing elementMap will |
|
104 | - * be overridden while parsing the tree, and restored after this process. |
|
105 | - */ |
|
106 | - public function parseGetElements(array $elementMap = null): array |
|
107 | - { |
|
108 | - $result = $this->parseInnerTree($elementMap); |
|
109 | - if (!is_array($result)) { |
|
110 | - return []; |
|
111 | - } |
|
112 | - |
|
113 | - return $result; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Parses all elements below the current element. |
|
118 | - * |
|
119 | - * This method will return a string if this was a text-node, or an array if |
|
120 | - * there were sub-elements. |
|
121 | - * |
|
122 | - * If there's both text and sub-elements, the text will be discarded. |
|
123 | - * |
|
124 | - * If the $elementMap argument is specified, the existing elementMap will |
|
125 | - * be overridden while parsing the tree, and restored after this process. |
|
126 | - * |
|
127 | - * @return array|string|null |
|
128 | - */ |
|
129 | - public function parseInnerTree(array $elementMap = null) |
|
130 | - { |
|
131 | - $text = null; |
|
132 | - $elements = []; |
|
133 | - |
|
134 | - if (self::ELEMENT === $this->nodeType && $this->isEmptyElement) { |
|
135 | - // Easy! |
|
136 | - $this->next(); |
|
137 | - |
|
138 | - return null; |
|
139 | - } |
|
140 | - |
|
141 | - if (!is_null($elementMap)) { |
|
142 | - $this->pushContext(); |
|
143 | - $this->elementMap = $elementMap; |
|
144 | - } |
|
145 | - |
|
146 | - try { |
|
147 | - if (!$this->read()) { |
|
148 | - $errors = libxml_get_errors(); |
|
149 | - libxml_clear_errors(); |
|
150 | - if ($errors) { |
|
151 | - throw new LibXMLException($errors); |
|
152 | - } |
|
153 | - throw new ParseException('This should never happen (famous last words)'); |
|
154 | - } |
|
155 | - |
|
156 | - $keepOnParsing = true; |
|
157 | - |
|
158 | - while ($keepOnParsing) { |
|
159 | - if (!$this->isValid()) { |
|
160 | - $errors = libxml_get_errors(); |
|
161 | - |
|
162 | - if ($errors) { |
|
163 | - libxml_clear_errors(); |
|
164 | - throw new LibXMLException($errors); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - switch ($this->nodeType) { |
|
169 | - case self::ELEMENT: |
|
170 | - $elements[] = $this->parseCurrentElement(); |
|
171 | - break; |
|
172 | - case self::TEXT: |
|
173 | - case self::CDATA: |
|
174 | - $text .= $this->value; |
|
175 | - $this->read(); |
|
176 | - break; |
|
177 | - case self::END_ELEMENT: |
|
178 | - // Ensuring we are moving the cursor after the end element. |
|
179 | - $this->read(); |
|
180 | - $keepOnParsing = false; |
|
181 | - break; |
|
182 | - case self::NONE: |
|
183 | - throw new ParseException('We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.'); |
|
184 | - default: |
|
185 | - // Advance to the next element |
|
186 | - $this->read(); |
|
187 | - break; |
|
188 | - } |
|
189 | - } |
|
190 | - } finally { |
|
191 | - if (!is_null($elementMap)) { |
|
192 | - $this->popContext(); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - return $elements ? $elements : $text; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Reads all text below the current element, and returns this as a string. |
|
201 | - */ |
|
202 | - public function readText(): string |
|
203 | - { |
|
204 | - $result = ''; |
|
205 | - $previousDepth = $this->depth; |
|
206 | - |
|
207 | - while ($this->read() && $this->depth != $previousDepth) { |
|
208 | - if (in_array($this->nodeType, [XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE])) { |
|
209 | - $result .= $this->value; |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - return $result; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Parses the current XML element. |
|
218 | - * |
|
219 | - * This method returns arn array with 3 properties: |
|
220 | - * * name - A clark-notation XML element name. |
|
221 | - * * value - The parsed value. |
|
222 | - * * attributes - A key-value list of attributes. |
|
223 | - */ |
|
224 | - public function parseCurrentElement(): array |
|
225 | - { |
|
226 | - $name = $this->getClark(); |
|
227 | - |
|
228 | - $attributes = []; |
|
229 | - |
|
230 | - if ($this->hasAttributes) { |
|
231 | - $attributes = $this->parseAttributes(); |
|
232 | - } |
|
233 | - |
|
234 | - $value = call_user_func( |
|
235 | - $this->getDeserializerForElementName((string) $name), |
|
236 | - $this |
|
237 | - ); |
|
238 | - |
|
239 | - return [ |
|
240 | - 'name' => $name, |
|
241 | - 'value' => $value, |
|
242 | - 'attributes' => $attributes, |
|
243 | - ]; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Grabs all the attributes from the current element, and returns them as a |
|
248 | - * key-value array. |
|
249 | - * |
|
250 | - * If the attributes are part of the same namespace, they will simply be |
|
251 | - * short keys. If they are defined on a different namespace, the attribute |
|
252 | - * name will be returned in clark-notation. |
|
253 | - */ |
|
254 | - public function parseAttributes(): array |
|
255 | - { |
|
256 | - $attributes = []; |
|
257 | - |
|
258 | - while ($this->moveToNextAttribute()) { |
|
259 | - if ($this->namespaceURI) { |
|
260 | - // Ignoring 'xmlns', it doesn't make any sense. |
|
261 | - if ('http://www.w3.org/2000/xmlns/' === $this->namespaceURI) { |
|
262 | - continue; |
|
263 | - } |
|
264 | - |
|
265 | - $name = $this->getClark(); |
|
266 | - $attributes[$name] = $this->value; |
|
267 | - } else { |
|
268 | - $attributes[$this->localName] = $this->value; |
|
269 | - } |
|
270 | - } |
|
271 | - $this->moveToElement(); |
|
272 | - |
|
273 | - return $attributes; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Returns the function that should be used to parse the element identified |
|
278 | - * by its clark-notation name. |
|
279 | - */ |
|
280 | - public function getDeserializerForElementName(string $name): callable |
|
281 | - { |
|
282 | - if (!array_key_exists($name, $this->elementMap)) { |
|
283 | - if ('{}' == substr($name, 0, 2) && array_key_exists(substr($name, 2), $this->elementMap)) { |
|
284 | - $name = substr($name, 2); |
|
285 | - } else { |
|
286 | - return ['Sabre\\Xml\\Element\\Base', 'xmlDeserialize']; |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - $deserializer = $this->elementMap[$name]; |
|
291 | - if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
|
292 | - return [$deserializer, 'xmlDeserialize']; |
|
293 | - } |
|
294 | - |
|
295 | - if (is_callable($deserializer)) { |
|
296 | - return $deserializer; |
|
297 | - } |
|
298 | - |
|
299 | - $type = gettype($deserializer); |
|
300 | - if ('string' === $type) { |
|
301 | - $type .= ' ('.$deserializer.')'; |
|
302 | - } elseif ('object' === $type) { |
|
303 | - $type .= ' ('.get_class($deserializer).')'; |
|
304 | - } |
|
305 | - throw new \LogicException('Could not use this type as a deserializer: '.$type.' for element: '.$name); |
|
306 | - } |
|
24 | + use ContextStackTrait; |
|
25 | + |
|
26 | + /** |
|
27 | + * Returns the current nodename in clark-notation. |
|
28 | + * |
|
29 | + * For example: "{http://www.w3.org/2005/Atom}feed". |
|
30 | + * Or if no namespace is defined: "{}feed". |
|
31 | + * |
|
32 | + * This method returns null if we're not currently on an element. |
|
33 | + * |
|
34 | + * @return string|null |
|
35 | + */ |
|
36 | + public function getClark() |
|
37 | + { |
|
38 | + if (!$this->localName) { |
|
39 | + return null; |
|
40 | + } |
|
41 | + |
|
42 | + return '{'.$this->namespaceURI.'}'.$this->localName; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Reads the entire document. |
|
47 | + * |
|
48 | + * This function returns an array with the following three elements: |
|
49 | + * * name - The root element name. |
|
50 | + * * value - The value for the root element. |
|
51 | + * * attributes - An array of attributes. |
|
52 | + * |
|
53 | + * This function will also disable the standard libxml error handler (which |
|
54 | + * usually just results in PHP errors), and throw exceptions instead. |
|
55 | + */ |
|
56 | + public function parse(): array |
|
57 | + { |
|
58 | + $previousEntityState = null; |
|
59 | + $shouldCallLibxmlDisableEntityLoader = (\LIBXML_VERSION < 20900); |
|
60 | + if ($shouldCallLibxmlDisableEntityLoader) { |
|
61 | + $previousEntityState = libxml_disable_entity_loader(true); |
|
62 | + } |
|
63 | + $previousSetting = libxml_use_internal_errors(true); |
|
64 | + |
|
65 | + try { |
|
66 | + while (self::ELEMENT !== $this->nodeType) { |
|
67 | + if (!$this->read()) { |
|
68 | + $errors = libxml_get_errors(); |
|
69 | + libxml_clear_errors(); |
|
70 | + if ($errors) { |
|
71 | + throw new LibXMLException($errors); |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + $result = $this->parseCurrentElement(); |
|
76 | + |
|
77 | + // last line of defense in case errors did occur above |
|
78 | + $errors = libxml_get_errors(); |
|
79 | + libxml_clear_errors(); |
|
80 | + if ($errors) { |
|
81 | + throw new LibXMLException($errors); |
|
82 | + } |
|
83 | + } finally { |
|
84 | + libxml_use_internal_errors($previousSetting); |
|
85 | + if ($shouldCallLibxmlDisableEntityLoader) { |
|
86 | + libxml_disable_entity_loader($previousEntityState); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + return $result; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * parseGetElements parses everything in the current sub-tree, |
|
95 | + * and returns an array of elements. |
|
96 | + * |
|
97 | + * Each element has a 'name', 'value' and 'attributes' key. |
|
98 | + * |
|
99 | + * If the element didn't contain sub-elements, an empty array is always |
|
100 | + * returned. If there was any text inside the element, it will be |
|
101 | + * discarded. |
|
102 | + * |
|
103 | + * If the $elementMap argument is specified, the existing elementMap will |
|
104 | + * be overridden while parsing the tree, and restored after this process. |
|
105 | + */ |
|
106 | + public function parseGetElements(array $elementMap = null): array |
|
107 | + { |
|
108 | + $result = $this->parseInnerTree($elementMap); |
|
109 | + if (!is_array($result)) { |
|
110 | + return []; |
|
111 | + } |
|
112 | + |
|
113 | + return $result; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Parses all elements below the current element. |
|
118 | + * |
|
119 | + * This method will return a string if this was a text-node, or an array if |
|
120 | + * there were sub-elements. |
|
121 | + * |
|
122 | + * If there's both text and sub-elements, the text will be discarded. |
|
123 | + * |
|
124 | + * If the $elementMap argument is specified, the existing elementMap will |
|
125 | + * be overridden while parsing the tree, and restored after this process. |
|
126 | + * |
|
127 | + * @return array|string|null |
|
128 | + */ |
|
129 | + public function parseInnerTree(array $elementMap = null) |
|
130 | + { |
|
131 | + $text = null; |
|
132 | + $elements = []; |
|
133 | + |
|
134 | + if (self::ELEMENT === $this->nodeType && $this->isEmptyElement) { |
|
135 | + // Easy! |
|
136 | + $this->next(); |
|
137 | + |
|
138 | + return null; |
|
139 | + } |
|
140 | + |
|
141 | + if (!is_null($elementMap)) { |
|
142 | + $this->pushContext(); |
|
143 | + $this->elementMap = $elementMap; |
|
144 | + } |
|
145 | + |
|
146 | + try { |
|
147 | + if (!$this->read()) { |
|
148 | + $errors = libxml_get_errors(); |
|
149 | + libxml_clear_errors(); |
|
150 | + if ($errors) { |
|
151 | + throw new LibXMLException($errors); |
|
152 | + } |
|
153 | + throw new ParseException('This should never happen (famous last words)'); |
|
154 | + } |
|
155 | + |
|
156 | + $keepOnParsing = true; |
|
157 | + |
|
158 | + while ($keepOnParsing) { |
|
159 | + if (!$this->isValid()) { |
|
160 | + $errors = libxml_get_errors(); |
|
161 | + |
|
162 | + if ($errors) { |
|
163 | + libxml_clear_errors(); |
|
164 | + throw new LibXMLException($errors); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + switch ($this->nodeType) { |
|
169 | + case self::ELEMENT: |
|
170 | + $elements[] = $this->parseCurrentElement(); |
|
171 | + break; |
|
172 | + case self::TEXT: |
|
173 | + case self::CDATA: |
|
174 | + $text .= $this->value; |
|
175 | + $this->read(); |
|
176 | + break; |
|
177 | + case self::END_ELEMENT: |
|
178 | + // Ensuring we are moving the cursor after the end element. |
|
179 | + $this->read(); |
|
180 | + $keepOnParsing = false; |
|
181 | + break; |
|
182 | + case self::NONE: |
|
183 | + throw new ParseException('We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.'); |
|
184 | + default: |
|
185 | + // Advance to the next element |
|
186 | + $this->read(); |
|
187 | + break; |
|
188 | + } |
|
189 | + } |
|
190 | + } finally { |
|
191 | + if (!is_null($elementMap)) { |
|
192 | + $this->popContext(); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + return $elements ? $elements : $text; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Reads all text below the current element, and returns this as a string. |
|
201 | + */ |
|
202 | + public function readText(): string |
|
203 | + { |
|
204 | + $result = ''; |
|
205 | + $previousDepth = $this->depth; |
|
206 | + |
|
207 | + while ($this->read() && $this->depth != $previousDepth) { |
|
208 | + if (in_array($this->nodeType, [XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE])) { |
|
209 | + $result .= $this->value; |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + return $result; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Parses the current XML element. |
|
218 | + * |
|
219 | + * This method returns arn array with 3 properties: |
|
220 | + * * name - A clark-notation XML element name. |
|
221 | + * * value - The parsed value. |
|
222 | + * * attributes - A key-value list of attributes. |
|
223 | + */ |
|
224 | + public function parseCurrentElement(): array |
|
225 | + { |
|
226 | + $name = $this->getClark(); |
|
227 | + |
|
228 | + $attributes = []; |
|
229 | + |
|
230 | + if ($this->hasAttributes) { |
|
231 | + $attributes = $this->parseAttributes(); |
|
232 | + } |
|
233 | + |
|
234 | + $value = call_user_func( |
|
235 | + $this->getDeserializerForElementName((string) $name), |
|
236 | + $this |
|
237 | + ); |
|
238 | + |
|
239 | + return [ |
|
240 | + 'name' => $name, |
|
241 | + 'value' => $value, |
|
242 | + 'attributes' => $attributes, |
|
243 | + ]; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Grabs all the attributes from the current element, and returns them as a |
|
248 | + * key-value array. |
|
249 | + * |
|
250 | + * If the attributes are part of the same namespace, they will simply be |
|
251 | + * short keys. If they are defined on a different namespace, the attribute |
|
252 | + * name will be returned in clark-notation. |
|
253 | + */ |
|
254 | + public function parseAttributes(): array |
|
255 | + { |
|
256 | + $attributes = []; |
|
257 | + |
|
258 | + while ($this->moveToNextAttribute()) { |
|
259 | + if ($this->namespaceURI) { |
|
260 | + // Ignoring 'xmlns', it doesn't make any sense. |
|
261 | + if ('http://www.w3.org/2000/xmlns/' === $this->namespaceURI) { |
|
262 | + continue; |
|
263 | + } |
|
264 | + |
|
265 | + $name = $this->getClark(); |
|
266 | + $attributes[$name] = $this->value; |
|
267 | + } else { |
|
268 | + $attributes[$this->localName] = $this->value; |
|
269 | + } |
|
270 | + } |
|
271 | + $this->moveToElement(); |
|
272 | + |
|
273 | + return $attributes; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Returns the function that should be used to parse the element identified |
|
278 | + * by its clark-notation name. |
|
279 | + */ |
|
280 | + public function getDeserializerForElementName(string $name): callable |
|
281 | + { |
|
282 | + if (!array_key_exists($name, $this->elementMap)) { |
|
283 | + if ('{}' == substr($name, 0, 2) && array_key_exists(substr($name, 2), $this->elementMap)) { |
|
284 | + $name = substr($name, 2); |
|
285 | + } else { |
|
286 | + return ['Sabre\\Xml\\Element\\Base', 'xmlDeserialize']; |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + $deserializer = $this->elementMap[$name]; |
|
291 | + if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
|
292 | + return [$deserializer, 'xmlDeserialize']; |
|
293 | + } |
|
294 | + |
|
295 | + if (is_callable($deserializer)) { |
|
296 | + return $deserializer; |
|
297 | + } |
|
298 | + |
|
299 | + $type = gettype($deserializer); |
|
300 | + if ('string' === $type) { |
|
301 | + $type .= ' ('.$deserializer.')'; |
|
302 | + } elseif ('object' === $type) { |
|
303 | + $type .= ' ('.get_class($deserializer).')'; |
|
304 | + } |
|
305 | + throw new \LogicException('Could not use this type as a deserializer: '.$type.' for element: '.$name); |
|
306 | + } |
|
307 | 307 | } |
@@ -14,21 +14,21 @@ |
||
14 | 14 | */ |
15 | 15 | interface XmlSerializable |
16 | 16 | { |
17 | - /** |
|
18 | - * The xmlSerialize method is called during xml writing. |
|
19 | - * |
|
20 | - * Use the $writer argument to write its own xml serialization. |
|
21 | - * |
|
22 | - * An important note: do _not_ create a parent element. Any element |
|
23 | - * implementing XmlSerializable should only ever write what's considered |
|
24 | - * its 'inner xml'. |
|
25 | - * |
|
26 | - * The parent of the current element is responsible for writing a |
|
27 | - * containing element. |
|
28 | - * |
|
29 | - * This allows serializers to be re-used for different element names. |
|
30 | - * |
|
31 | - * If you are opening new elements, you must also close them again. |
|
32 | - */ |
|
33 | - public function xmlSerialize(Writer $writer); |
|
17 | + /** |
|
18 | + * The xmlSerialize method is called during xml writing. |
|
19 | + * |
|
20 | + * Use the $writer argument to write its own xml serialization. |
|
21 | + * |
|
22 | + * An important note: do _not_ create a parent element. Any element |
|
23 | + * implementing XmlSerializable should only ever write what's considered |
|
24 | + * its 'inner xml'. |
|
25 | + * |
|
26 | + * The parent of the current element is responsible for writing a |
|
27 | + * containing element. |
|
28 | + * |
|
29 | + * This allows serializers to be re-used for different element names. |
|
30 | + * |
|
31 | + * If you are opening new elements, you must also close them again. |
|
32 | + */ |
|
33 | + public function xmlSerialize(Writer $writer); |
|
34 | 34 | } |
@@ -23,96 +23,96 @@ |
||
23 | 23 | */ |
24 | 24 | trait ContextStackTrait |
25 | 25 | { |
26 | - /** |
|
27 | - * This is the element map. It contains a list of XML elements (in clark |
|
28 | - * notation) as keys and PHP class names as values. |
|
29 | - * |
|
30 | - * The PHP class names must implement Sabre\Xml\Element. |
|
31 | - * |
|
32 | - * Values may also be a callable. In that case the function will be called |
|
33 | - * directly. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - public $elementMap = []; |
|
26 | + /** |
|
27 | + * This is the element map. It contains a list of XML elements (in clark |
|
28 | + * notation) as keys and PHP class names as values. |
|
29 | + * |
|
30 | + * The PHP class names must implement Sabre\Xml\Element. |
|
31 | + * |
|
32 | + * Values may also be a callable. In that case the function will be called |
|
33 | + * directly. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + public $elementMap = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * A contextUri pointing to the document being parsed / written. |
|
41 | - * This uri may be used to resolve relative urls that may appear in the |
|
42 | - * document. |
|
43 | - * |
|
44 | - * The reader and writer don't use this property, but as it's an extremely |
|
45 | - * common use-case for parsing XML documents, it's added here as a |
|
46 | - * convenience. |
|
47 | - * |
|
48 | - * @var string|null |
|
49 | - */ |
|
50 | - public $contextUri; |
|
39 | + /** |
|
40 | + * A contextUri pointing to the document being parsed / written. |
|
41 | + * This uri may be used to resolve relative urls that may appear in the |
|
42 | + * document. |
|
43 | + * |
|
44 | + * The reader and writer don't use this property, but as it's an extremely |
|
45 | + * common use-case for parsing XML documents, it's added here as a |
|
46 | + * convenience. |
|
47 | + * |
|
48 | + * @var string|null |
|
49 | + */ |
|
50 | + public $contextUri; |
|
51 | 51 | |
52 | - /** |
|
53 | - * This is a list of namespaces that you want to give default prefixes. |
|
54 | - * |
|
55 | - * You must make sure you create this entire list before starting to write. |
|
56 | - * They should be registered on the root element. |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - public $namespaceMap = []; |
|
52 | + /** |
|
53 | + * This is a list of namespaces that you want to give default prefixes. |
|
54 | + * |
|
55 | + * You must make sure you create this entire list before starting to write. |
|
56 | + * They should be registered on the root element. |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + public $namespaceMap = []; |
|
61 | 61 | |
62 | - /** |
|
63 | - * This is a list of custom serializers for specific classes. |
|
64 | - * |
|
65 | - * The writer may use this if you attempt to serialize an object with a |
|
66 | - * class that does not implement XmlSerializable. |
|
67 | - * |
|
68 | - * Instead it will look at this classmap to see if there is a custom |
|
69 | - * serializer here. This is useful if you don't want your value objects |
|
70 | - * to be responsible for serializing themselves. |
|
71 | - * |
|
72 | - * The keys in this classmap need to be fully qualified PHP class names, |
|
73 | - * the values must be callbacks. The callbacks take two arguments. The |
|
74 | - * writer class, and the value that must be written. |
|
75 | - * |
|
76 | - * function (Writer $writer, object $value) |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - public $classMap = []; |
|
62 | + /** |
|
63 | + * This is a list of custom serializers for specific classes. |
|
64 | + * |
|
65 | + * The writer may use this if you attempt to serialize an object with a |
|
66 | + * class that does not implement XmlSerializable. |
|
67 | + * |
|
68 | + * Instead it will look at this classmap to see if there is a custom |
|
69 | + * serializer here. This is useful if you don't want your value objects |
|
70 | + * to be responsible for serializing themselves. |
|
71 | + * |
|
72 | + * The keys in this classmap need to be fully qualified PHP class names, |
|
73 | + * the values must be callbacks. The callbacks take two arguments. The |
|
74 | + * writer class, and the value that must be written. |
|
75 | + * |
|
76 | + * function (Writer $writer, object $value) |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + public $classMap = []; |
|
81 | 81 | |
82 | - /** |
|
83 | - * Backups of previous contexts. |
|
84 | - * |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - protected $contextStack = []; |
|
82 | + /** |
|
83 | + * Backups of previous contexts. |
|
84 | + * |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + protected $contextStack = []; |
|
88 | 88 | |
89 | - /** |
|
90 | - * Create a new "context". |
|
91 | - * |
|
92 | - * This allows you to safely modify the elementMap, contextUri or |
|
93 | - * namespaceMap. After you're done, you can restore the old data again |
|
94 | - * with popContext. |
|
95 | - */ |
|
96 | - public function pushContext() |
|
97 | - { |
|
98 | - $this->contextStack[] = [ |
|
99 | - $this->elementMap, |
|
100 | - $this->contextUri, |
|
101 | - $this->namespaceMap, |
|
102 | - $this->classMap, |
|
103 | - ]; |
|
104 | - } |
|
89 | + /** |
|
90 | + * Create a new "context". |
|
91 | + * |
|
92 | + * This allows you to safely modify the elementMap, contextUri or |
|
93 | + * namespaceMap. After you're done, you can restore the old data again |
|
94 | + * with popContext. |
|
95 | + */ |
|
96 | + public function pushContext() |
|
97 | + { |
|
98 | + $this->contextStack[] = [ |
|
99 | + $this->elementMap, |
|
100 | + $this->contextUri, |
|
101 | + $this->namespaceMap, |
|
102 | + $this->classMap, |
|
103 | + ]; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Restore the previous "context". |
|
108 | - */ |
|
109 | - public function popContext() |
|
110 | - { |
|
111 | - list( |
|
112 | - $this->elementMap, |
|
113 | - $this->contextUri, |
|
114 | - $this->namespaceMap, |
|
115 | - $this->classMap |
|
116 | - ) = array_pop($this->contextStack); |
|
117 | - } |
|
106 | + /** |
|
107 | + * Restore the previous "context". |
|
108 | + */ |
|
109 | + public function popContext() |
|
110 | + { |
|
111 | + list( |
|
112 | + $this->elementMap, |
|
113 | + $this->contextUri, |
|
114 | + $this->namespaceMap, |
|
115 | + $this->classMap |
|
116 | + ) = array_pop($this->contextStack); |
|
117 | + } |
|
118 | 118 | } |
@@ -25,8 +25,9 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public static function contains($haystack, $needle, $caseSensitive = true) |
27 | 27 | { |
28 | - if (empty($needle)) |
|
29 | - return true; |
|
28 | + if (empty($needle)) { |
|
29 | + return true; |
|
30 | + } |
|
30 | 31 | return $caseSensitive |
31 | 32 | ? strpos($haystack, $needle) !== false |
32 | 33 | : stripos($haystack, $needle) !== false; |
@@ -62,7 +63,9 @@ discard block |
||
62 | 63 | } |
63 | 64 | |
64 | 65 | // @CHANGE LDR |
65 | - if (!is_string($haystack)) return false; |
|
66 | + if (!is_string($haystack)) { |
|
67 | + return false; |
|
68 | + } |
|
66 | 69 | |
67 | 70 | return (substr($haystack, -$length) === $needle); |
68 | 71 | } |
@@ -14,21 +14,21 @@ |
||
14 | 14 | */ |
15 | 15 | class Arr |
16 | 16 | { |
17 | - /** |
|
18 | - * Deep copy given array |
|
19 | - * |
|
20 | - * @param array $arr |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public static function copy(array $arr) |
|
25 | - { |
|
26 | - $copy = array(); |
|
27 | - foreach ($arr as $key => $value) { |
|
28 | - if (is_array($value)) $copy[$key] = static::copy($value); |
|
29 | - else if (is_object($value)) $copy[$key] = clone $value; |
|
30 | - else $copy[$key] = $value; |
|
31 | - } |
|
32 | - return $copy; |
|
33 | - } |
|
17 | + /** |
|
18 | + * Deep copy given array |
|
19 | + * |
|
20 | + * @param array $arr |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public static function copy(array $arr) |
|
25 | + { |
|
26 | + $copy = array(); |
|
27 | + foreach ($arr as $key => $value) { |
|
28 | + if (is_array($value)) $copy[$key] = static::copy($value); |
|
29 | + else if (is_object($value)) $copy[$key] = clone $value; |
|
30 | + else $copy[$key] = $value; |
|
31 | + } |
|
32 | + return $copy; |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -25,9 +25,13 @@ |
||
25 | 25 | { |
26 | 26 | $copy = array(); |
27 | 27 | foreach ($arr as $key => $value) { |
28 | - if (is_array($value)) $copy[$key] = static::copy($value); |
|
29 | - else if (is_object($value)) $copy[$key] = clone $value; |
|
30 | - else $copy[$key] = $value; |
|
28 | + if (is_array($value)) { |
|
29 | + $copy[$key] = static::copy($value); |
|
30 | + } else if (is_object($value)) { |
|
31 | + $copy[$key] = clone $value; |
|
32 | + } else { |
|
33 | + $copy[$key] = $value; |
|
34 | + } |
|
31 | 35 | } |
32 | 36 | return $copy; |
33 | 37 | } |
@@ -14,19 +14,19 @@ |
||
14 | 14 | */ |
15 | 15 | interface iValidate { |
16 | 16 | |
17 | - /** |
|
18 | - * method used for validation. |
|
19 | - * |
|
20 | - * @param mixed $input |
|
21 | - * data that needs to be validated |
|
22 | - * @param ValidationInfo $info |
|
23 | - * information to be used for validation |
|
24 | - * @return boolean false in case of failure or fixed value in the expected |
|
25 | - * type |
|
26 | - * @throws \Luracast\Restler\RestException 400 with information about the |
|
27 | - * failed |
|
28 | - * validation |
|
29 | - */ |
|
30 | - public static function validate($input, ValidationInfo $info); |
|
17 | + /** |
|
18 | + * method used for validation. |
|
19 | + * |
|
20 | + * @param mixed $input |
|
21 | + * data that needs to be validated |
|
22 | + * @param ValidationInfo $info |
|
23 | + * information to be used for validation |
|
24 | + * @return boolean false in case of failure or fixed value in the expected |
|
25 | + * type |
|
26 | + * @throws \Luracast\Restler\RestException 400 with information about the |
|
27 | + * failed |
|
28 | + * validation |
|
29 | + */ |
|
30 | + public static function validate($input, ValidationInfo $info); |
|
31 | 31 | } |
32 | 32 |