Service
extends Service
in package
XML service for WebDAV.
Tags
Table of Contents
- $classMap : array<string|int, mixed>
- This is a list of custom serializers for specific classes.
- $elementMap : array<string|int, mixed>
- This is a list of XML elements that we automatically map to PHP classes.
- $namespaceMap : array<string|int, mixed>
- This is a default list of namespaces.
- $options : int
- A bitmask of the LIBXML_* constants.
- $valueObjectMap : mixed
- A list of classes and which XML elements they map to.
- expect() : array<string|int, mixed>|object|string
- Parses a document in full, and specify what the expected root element name is.
- getReader() : Reader
- Returns a fresh XML Reader.
- getWriter() : Writer
- Returns a fresh xml writer.
- mapValueObject() : mixed
- Map an xml element to a PHP class.
- parse() : array<string|int, mixed>|object|string
- Parses a document in full.
- parseClarkNotation() : array<string|int, mixed>
- Parses a clark-notation string, and returns the namespace and element name components.
- write() : string
- Generates an XML document in one go.
- writeValueObject() : mixed
- Writes a value object.
Properties
$classMap
This is a list of custom serializers for specific classes.
public
array<string|int, mixed>
$classMap
= []
The writer may use this if you attempt to serialize an object with a class that does not implement XmlSerializable.
Instead it will look at this classmap to see if there is a custom serializer here. This is useful if you don't want your value objects to be responsible for serializing themselves.
The keys in this classmap need to be fully qualified PHP class names, the values must be callbacks. The callbacks take two arguments. The writer class, and the value that must be written.
function (Writer $writer, object $value)
$elementMap
This is a list of XML elements that we automatically map to PHP classes.
public
array<string|int, mixed>
$elementMap
= [
'{DAV:}multistatus' => 'Sabre\DAV\Xml\Response\MultiStatus',
'{DAV:}response' => 'Sabre\DAV\Xml\Element\Response',
// Requests
'{DAV:}propfind' => 'Sabre\DAV\Xml\Request\PropFind',
'{DAV:}propertyupdate' => 'Sabre\DAV\Xml\Request\PropPatch',
'{DAV:}mkcol' => 'Sabre\DAV\Xml\Request\MkCol',
// Properties
'{DAV:}resourcetype' => 'Sabre\DAV\Xml\Property\ResourceType',
]
For instance, this list may contain an entry {DAV:}propfind that would
be mapped to Sabre\DAV\Xml\Request\PropFind
$namespaceMap
This is a default list of namespaces.
public
array<string|int, mixed>
$namespaceMap
= ['DAV:' => 'd', 'http://sabredav.org/ns' => 's']
If you are defining your own custom namespace, add it here to reduce bandwidth and improve legibility of xml bodies.
$options
A bitmask of the LIBXML_* constants.
public
int
$options
= 0
$valueObjectMap
A list of classes and which XML elements they map to.
protected
mixed
$valueObjectMap
= []
Methods
expect()
Parses a document in full, and specify what the expected root element name is.
public
expect(string|array<string|int, string> $rootElementName, string|resource $input[, string $contextUri = null ]) : array<string|int, mixed>|object|string
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.
Parameters
- $rootElementName : string|array<string|int, string>
- $input : string|resource
- $contextUri : string = null
Tags
Return values
array<string|int, mixed>|object|string —getReader()
Returns a fresh XML Reader.
public
getReader() : Reader
Return values
Reader —getWriter()
Returns a fresh xml writer.
public
getWriter() : Writer
Return values
Writer —mapValueObject()
Map an xml element to a PHP class.
public
mapValueObject(string $elementName, string $className) : mixed
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:
These can easily be mapped by calling:
$service->mapValueObject('{http://example.org}author', 'Author');
Parameters
- $elementName : string
- $className : string
Return values
mixed —parse()
Parses a document in full.
public
parse(string|resource $input[, string $contextUri = null ][, string &$rootElementName = null ]) : array<string|int, mixed>|object|string
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.
Parameters
- $input : string|resource
- $contextUri : string = null
- $rootElementName : string = null
Tags
Return values
array<string|int, mixed>|object|string —parseClarkNotation()
Parses a clark-notation string, and returns the namespace and element name components.
public
static parseClarkNotation(string $str) : array<string|int, mixed>
If the string was invalid, it will throw an InvalidArgumentException.
Parameters
- $str : string
Tags
Return values
array<string|int, mixed> —write()
Generates an XML document in one go.
public
write(string $rootElementName, string|array<string|int, mixed>|object|XmlSerializable $value[, string $contextUri = null ]) : string
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.
Parameters
- $rootElementName : string
- $value : string|array<string|int, mixed>|object|XmlSerializable
- $contextUri : string = null
Return values
string —writeValueObject()
Writes a value object.
public
writeValueObject(object $object[, string $contextUri = null ]) : mixed
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().
Parameters
- $object : object
- $contextUri : string = null