1 | <?php |
||
13 | class XmlVisitor extends AbstractRequestVisitor |
||
14 | { |
||
15 | /** @var \SplObjectStorage Data object for persisting XML data */ |
||
16 | protected $data; |
||
17 | |||
18 | /** @var bool Content-Type header added when XML is found */ |
||
19 | protected $contentType = 'application/xml'; |
||
20 | |||
21 | public function __construct() |
||
25 | |||
26 | /** |
||
27 | * Change the content-type header that is added when XML is found |
||
28 | * |
||
29 | * @param string $header Header to set when XML is found |
||
30 | * |
||
31 | * @return self |
||
32 | */ |
||
33 | public function setContentTypeHeader($header) |
||
39 | |||
40 | public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) |
||
49 | |||
50 | public function after(CommandInterface $command, RequestInterface $request) |
||
75 | |||
76 | /** |
||
77 | * Create the root XML element to use with a request |
||
78 | * |
||
79 | * @param Operation $operation Operation object |
||
80 | * |
||
81 | * @return \XMLWriter |
||
82 | */ |
||
83 | protected function createRootElement(Operation $operation) |
||
107 | |||
108 | /** |
||
109 | * Recursively build the XML body |
||
110 | * |
||
111 | * @param \XMLWriter $xmlWriter XML to modify |
||
112 | * @param Parameter $param API Parameter |
||
113 | * @param mixed $value Value to add |
||
114 | */ |
||
115 | protected function addXml(\XMLWriter $xmlWriter, Parameter $param, $value) |
||
150 | |||
151 | /** |
||
152 | * Write an attribute with namespace if used |
||
153 | * |
||
154 | * @param \XMLWriter $xmlWriter XMLWriter instance |
||
155 | * @param string $prefix Namespace prefix if any |
||
156 | * @param string $name Attribute name |
||
157 | * @param string $namespace The uri of the namespace |
||
158 | * @param string $value The attribute content |
||
159 | */ |
||
160 | protected function writeAttribute($xmlWriter, $prefix, $name, $namespace, $value) |
||
168 | |||
169 | /** |
||
170 | * Write an element with namespace if used |
||
171 | * |
||
172 | * @param \XMLWriter $xmlWriter XML writer resource |
||
173 | * @param string $prefix Namespace prefix if any |
||
174 | * @param string $name Element name |
||
175 | * @param string $namespace The uri of the namespace |
||
176 | * @param string $value The element content |
||
177 | */ |
||
178 | protected function writeElement(\XMLWriter $xmlWriter, $prefix, $name, $namespace, $value) |
||
188 | |||
189 | /** |
||
190 | * Create a new xml writer and start a document |
||
191 | * |
||
192 | * @param string $encoding document encoding |
||
193 | * |
||
194 | * @return \XMLWriter the writer resource |
||
195 | */ |
||
196 | protected function startDocument($encoding) |
||
204 | |||
205 | /** |
||
206 | * End the document and return the output |
||
207 | * |
||
208 | * @param \XMLWriter $xmlWriter |
||
209 | * |
||
210 | * @return \string the writer resource |
||
211 | */ |
||
212 | protected function finishDocument($xmlWriter) |
||
218 | |||
219 | /** |
||
220 | * Add an array to the XML |
||
221 | */ |
||
222 | protected function addXmlArray(\XMLWriter $xmlWriter, Parameter $param, &$value) |
||
230 | |||
231 | /** |
||
232 | * Add an object to the XML |
||
233 | */ |
||
234 | protected function addXmlObject(\XMLWriter $xmlWriter, Parameter $param, &$value) |
||
252 | } |
||
253 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.