Mercurial > hg > isophonics-drupal-site
comparison vendor/consolidation/output-formatters/src/StructuredData/Xml/XmlSchemaInterface.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Consolidation\OutputFormatters\StructuredData\Xml; | |
4 | |
5 /** | |
6 * When using arrays, we could represent XML data in a number of | |
7 * different ways. | |
8 * | |
9 * For example, given the following XML data strucutre: | |
10 * | |
11 * <document id="1" name="doc"> | |
12 * <foobars> | |
13 * <foobar id="123"> | |
14 * <name>blah</name> | |
15 * <widgets> | |
16 * <widget> | |
17 * <foo>a</foo> | |
18 * <bar>b</bar> | |
19 * <baz>c</baz> | |
20 * </widget> | |
21 * </widgets> | |
22 * </foobar> | |
23 * </foobars> | |
24 * </document> | |
25 * | |
26 * This could be: | |
27 * | |
28 * [ | |
29 * 'id' => 1, | |
30 * 'name' => 'doc', | |
31 * 'foobars' => | |
32 * [ | |
33 * [ | |
34 * 'id' => '123', | |
35 * 'name' => 'blah', | |
36 * 'widgets' => | |
37 * [ | |
38 * [ | |
39 * 'foo' => 'a', | |
40 * 'bar' => 'b', | |
41 * 'baz' => 'c', | |
42 * ] | |
43 * ], | |
44 * ], | |
45 * ] | |
46 * ] | |
47 * | |
48 * The challenge is more in going from an array back to the more | |
49 * structured xml format. Note that any given key => string mapping | |
50 * could represent either an attribute, or a simple XML element | |
51 * containing only a string value. In general, we do *not* want to add | |
52 * extra layers of nesting in the data structure to disambiguate between | |
53 * these kinds of data, as we want the source data to render cleanly | |
54 * into other formats, e.g. yaml, json, et. al., and we do not want to | |
55 * force every data provider to have to consider the optimal xml schema | |
56 * for their data. | |
57 * | |
58 * Our strategy, therefore, is to expect clients that wish to provide | |
59 * a very specific xml representation to return a DOMDocument, and, | |
60 * for other data structures where xml is a secondary concern, then we | |
61 * will use some default heuristics to convert from arrays to xml. | |
62 */ | |
63 interface XmlSchemaInterface | |
64 { | |
65 /** | |
66 * Convert data to a format suitable for use in a list. | |
67 * By default, the array values will be used. Implement | |
68 * ListDataInterface to use some other criteria (e.g. array keys). | |
69 * | |
70 * @return \DOMDocument | |
71 */ | |
72 public function arrayToXml($structuredData); | |
73 } |