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