ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
|
XML parsing and writing service. More...
Public Member Functions | |
getReader () | |
Returns a fresh XML Reader. More... | |
getWriter () | |
Returns a fresh xml writer. More... | |
parse ($input, $contextUri=null, &$rootElementName=null) | |
Parses a document in full. More... | |
expect ($rootElementName, $input, $contextUri=null) | |
Parses a document in full, and specify what the expected root element name is. More... | |
write ($rootElementName, $value, $contextUri=null) | |
Generates an XML document in one go. More... | |
mapValueObject ($elementName, $className) | |
Map an xml element to a PHP class. More... | |
writeValueObject ($object, $contextUri=null) | |
Writes a value object. More... | |
Static Public Member Functions | |
static | parseClarkNotation ($str) |
Parses a clark-notation string, and returns the namespace and element name components. More... | |
Data Fields | |
$elementMap = [] | |
$namespaceMap = [] | |
$classMap = [] | |
Protected Attributes | |
$valueObjectMap = [] | |
A list of classes and which XML elements they map to. More... | |
XML parsing and writing service.
You are encouraged to make a instance of this for your application and potentially extend it, as a central API point for dealing with xml and configuring the reader and writer.
Definition at line 16 of file Service.php.
Sabre\Xml\Service::expect | ( | $rootElementName, | |
$input, | |||
$contextUri = null |
|||
) |
Parses a document in full, and specify what the expected root element name is.
This function works similar to parse, but the difference is that the user can specify what the expected name of the root element should be, in clark notation.
This is useful in cases where you expected a specific document to be passed, and reduces the amount of if statements.
It's also possible to pass an array of expected rootElements if your code may expect more than one document type.
string|string[] | $rootElementName | |
string | resource | $input | |
string | null | $contextUri |
Definition at line 143 of file Service.php.
References Sabre\Xml\$contextUri, $input, $r, $result, and Sabre\Xml\Service\getReader().
Sabre\Xml\Service::getReader | ( | ) |
Definition at line 66 of file Service.php.
References Sabre\Xml\Service\$elementMap, and $r.
Referenced by Sabre\Xml\Service\expect(), and Sabre\Xml\Service\parse().
Sabre\Xml\Service::getWriter | ( | ) |
Returns a fresh xml writer.
Definition at line 79 of file Service.php.
References Sabre\Xml\Service\$classMap, Sabre\Xml\Service\$namespaceMap, and $w.
Referenced by Sabre\Xml\Service\write().
Sabre\Xml\Service::mapValueObject | ( | $elementName, | |
$className | |||
) |
Map an xml element to a PHP class.
Calling this function will automatically setup the Reader and Writer classes to turn a specific XML element to a PHP class.
For example, given a class such as :
class Author { public $firstName; public $lastName; }
and an XML element such as:
<author xmlns="http://example.org/ns"> <firstName>...</firstName> <lastName>...</lastName> </author>
These can easily be mapped by calling:
$service->mapValueObject('{http://example.org}author', 'Author');
string | $elementName | |
object | $className |
Definition at line 226 of file Service.php.
References $namespace, $reader, and Sabre\Xml\Deserializer\valueObject().
Sabre\Xml\Service::parse | ( | $input, | |
$contextUri = null , |
|||
& | $rootElementName = null |
||
) |
Parses a document in full.
Input may be specified as a string or readable stream resource. The returned value is the value of the root document.
Specifying the $contextUri allows the parser to figure out what the URI of the document was. This allows relative URIs within the document to be expanded easily.
The $rootElementName is specified by reference and will be populated with the root element name of the document.
string | resource | $input | |
string | null | $contextUri | |
string | null | $rootElementName |
ParseException |
Definition at line 107 of file Service.php.
References Sabre\Xml\$contextUri, $input, $r, $result, and Sabre\Xml\Service\getReader().
|
static |
Parses a clark-notation string, and returns the namespace and element name components.
If the string was invalid, it will throw an InvalidArgumentException.
string | $str |
InvalidArgumentException |
Definition at line 274 of file Service.php.
Referenced by Sabre\VObject\Parser\XML\getTagName(), Sabre\VObject\Parser\XML\parseProperties(), Sabre\DAV\Client\propFind(), Sabre\Xml\Writer\startElement(), Sabre\Xml\ServiceTest\testParseClarkNotation(), Sabre\Xml\ServiceTest\testParseClarkNotationFail(), and Sabre\Xml\Writer\writeAttribute().
Sabre\Xml\Service::write | ( | $rootElementName, | |
$value, | |||
$contextUri = null |
|||
) |
Generates an XML document in one go.
The $rootElement must be specified in clark notation. The value must be a string, an array or an object implementing XmlSerializable. Basically, anything that's supported by the Writer object.
$contextUri can be used to specify a sort of 'root' of the PHP application, in case the xml document is used as a http response.
This allows an implementor to easily create URI's relative to the root of the domain.
string | $rootElementName | |
string | array | XmlSerializable | $value | |
string | null | $contextUri |
Definition at line 186 of file Service.php.
References Sabre\Xml\$contextUri, $w, and Sabre\Xml\Service\getWriter().
Referenced by Sabre\Xml\Service\writeValueObject().
Sabre\Xml\Service::writeValueObject | ( | $object, | |
$contextUri = null |
|||
) |
Writes a value object.
This function largely behaves similar to write(), except that it's intended specifically to serialize a Value Object into an XML document.
The ValueObject must have been previously registered using mapValueObject().
object | $object | |
string | $contextUri |
Definition at line 251 of file Service.php.
References Sabre\Xml\$contextUri, and Sabre\Xml\Service\write().
Sabre\Xml\Service::$classMap = [] |
Definition at line 59 of file Service.php.
Referenced by Sabre\Xml\Service\getWriter().
Sabre\Xml\Service::$elementMap = [] |
Definition at line 29 of file Service.php.
Referenced by Sabre\Xml\Service\getReader().
Sabre\Xml\Service::$namespaceMap = [] |
Definition at line 39 of file Service.php.
Referenced by Sabre\Xml\Service\getWriter().
|
protected |
A list of classes and which XML elements they map to.
Definition at line 295 of file Service.php.