xref: /plugin/davcal/vendor/sabre/xml/lib/Element/Uri.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\Xml\Element;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\Xml;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehler/**
8*a1a3b679SAndreas Boehler * Uri element.
9*a1a3b679SAndreas Boehler *
10*a1a3b679SAndreas Boehler * This represents a single uri. An example of how this may be encoded:
11*a1a3b679SAndreas Boehler *
12*a1a3b679SAndreas Boehler *    <link>/foo/bar</link>
13*a1a3b679SAndreas Boehler *    <d:href xmlns:d="DAV:">http://example.org/hi</d:href>
14*a1a3b679SAndreas Boehler *
15*a1a3b679SAndreas Boehler * If the uri is relative, it will be automatically expanded to an absolute
16*a1a3b679SAndreas Boehler * url during writing and reading, if the contextUri property is set on the
17*a1a3b679SAndreas Boehler * reader and/or writer.
18*a1a3b679SAndreas Boehler *
19*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
20*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
21*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
22*a1a3b679SAndreas Boehler */
23*a1a3b679SAndreas Boehlerclass Uri implements Xml\Element {
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler    /**
26*a1a3b679SAndreas Boehler     * Uri element value.
27*a1a3b679SAndreas Boehler     *
28*a1a3b679SAndreas Boehler     * @var string
29*a1a3b679SAndreas Boehler     */
30*a1a3b679SAndreas Boehler    protected $value;
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    /**
33*a1a3b679SAndreas Boehler     * Constructor
34*a1a3b679SAndreas Boehler     *
35*a1a3b679SAndreas Boehler     * @param string $value
36*a1a3b679SAndreas Boehler     */
37*a1a3b679SAndreas Boehler    function __construct($value)
38*a1a3b679SAndreas Boehler    {
39*a1a3b679SAndreas Boehler        $this->value = $value;
40*a1a3b679SAndreas Boehler    }
41*a1a3b679SAndreas Boehler
42*a1a3b679SAndreas Boehler    /**
43*a1a3b679SAndreas Boehler     * The xmlSerialize metod is called during xml writing.
44*a1a3b679SAndreas Boehler     *
45*a1a3b679SAndreas Boehler     * Use the $writer argument to write its own xml serialization.
46*a1a3b679SAndreas Boehler     *
47*a1a3b679SAndreas Boehler     * An important note: do _not_ create a parent element. Any element
48*a1a3b679SAndreas Boehler     * implementing XmlSerializble should only ever write what's considered
49*a1a3b679SAndreas Boehler     * its 'inner xml'.
50*a1a3b679SAndreas Boehler     *
51*a1a3b679SAndreas Boehler     * The parent of the current element is responsible for writing a
52*a1a3b679SAndreas Boehler     * containing element.
53*a1a3b679SAndreas Boehler     *
54*a1a3b679SAndreas Boehler     * This allows serializers to be re-used for different element names.
55*a1a3b679SAndreas Boehler     *
56*a1a3b679SAndreas Boehler     * If you are opening new elements, you must also close them again.
57*a1a3b679SAndreas Boehler     *
58*a1a3b679SAndreas Boehler     * @param Writer $writer
59*a1a3b679SAndreas Boehler     * @return void
60*a1a3b679SAndreas Boehler     */
61*a1a3b679SAndreas Boehler    function xmlSerialize(Xml\Writer $writer) {
62*a1a3b679SAndreas Boehler
63*a1a3b679SAndreas Boehler        $writer->text(
64*a1a3b679SAndreas Boehler            \Sabre\Uri\resolve(
65*a1a3b679SAndreas Boehler                $writer->contextUri,
66*a1a3b679SAndreas Boehler                $this->value
67*a1a3b679SAndreas Boehler            )
68*a1a3b679SAndreas Boehler        );
69*a1a3b679SAndreas Boehler
70*a1a3b679SAndreas Boehler    }
71*a1a3b679SAndreas Boehler
72*a1a3b679SAndreas Boehler    /**
73*a1a3b679SAndreas Boehler     * This method is called during xml parsing.
74*a1a3b679SAndreas Boehler     *
75*a1a3b679SAndreas Boehler     * This method is called statically, this is because in theory this method
76*a1a3b679SAndreas Boehler     * may be used as a type of constructor, or factory method.
77*a1a3b679SAndreas Boehler     *
78*a1a3b679SAndreas Boehler     * Often you want to return an instance of the current class, but you are
79*a1a3b679SAndreas Boehler     * free to return other data as well.
80*a1a3b679SAndreas Boehler     *
81*a1a3b679SAndreas Boehler     * Important note 2: You are responsible for advancing the reader to the
82*a1a3b679SAndreas Boehler     * next element. Not doing anything will result in a never-ending loop.
83*a1a3b679SAndreas Boehler     *
84*a1a3b679SAndreas Boehler     * If you just want to skip parsing for this element altogether, you can
85*a1a3b679SAndreas Boehler     * just call $reader->next();
86*a1a3b679SAndreas Boehler     *
87*a1a3b679SAndreas Boehler     * $reader->parseSubTree() will parse the entire sub-tree, and advance to
88*a1a3b679SAndreas Boehler     * the next element.
89*a1a3b679SAndreas Boehler     *
90*a1a3b679SAndreas Boehler     * @param Xml\Reader $reader
91*a1a3b679SAndreas Boehler     * @return mixed
92*a1a3b679SAndreas Boehler     */
93*a1a3b679SAndreas Boehler    static function xmlDeserialize(Xml\Reader $reader) {
94*a1a3b679SAndreas Boehler
95*a1a3b679SAndreas Boehler        return new self(
96*a1a3b679SAndreas Boehler            \Sabre\Uri\resolve(
97*a1a3b679SAndreas Boehler                $reader->contextUri,
98*a1a3b679SAndreas Boehler                $reader->readText()
99*a1a3b679SAndreas Boehler            )
100*a1a3b679SAndreas Boehler        );
101*a1a3b679SAndreas Boehler
102*a1a3b679SAndreas Boehler    }
103*a1a3b679SAndreas Boehler
104*a1a3b679SAndreas Boehler}
105