1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Xml\Property; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\Xml\Element; 6*a1a3b679SAndreas Boehleruse Sabre\Xml\Reader; 7*a1a3b679SAndreas Boehleruse Sabre\Xml\Writer; 8*a1a3b679SAndreas Boehleruse Sabre\HTTP; 9*a1a3b679SAndreas Boehleruse DateTime; 10*a1a3b679SAndreas Boehleruse DateTimeZone; 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler/** 13*a1a3b679SAndreas Boehler * This property represents the {DAV:}getlastmodified property. 14*a1a3b679SAndreas Boehler * 15*a1a3b679SAndreas Boehler * Defined in: 16*a1a3b679SAndreas Boehler * http://tools.ietf.org/html/rfc4918#section-15.7 17*a1a3b679SAndreas Boehler * 18*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 19*a1a3b679SAndreas Boehler * @author Evert Pot (http://www.rooftopsolutions.nl/) 20*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 21*a1a3b679SAndreas Boehler */ 22*a1a3b679SAndreas Boehlerclass GetLastModified implements Element { 23*a1a3b679SAndreas Boehler 24*a1a3b679SAndreas Boehler /** 25*a1a3b679SAndreas Boehler * time 26*a1a3b679SAndreas Boehler * 27*a1a3b679SAndreas Boehler * @var DateTime 28*a1a3b679SAndreas Boehler */ 29*a1a3b679SAndreas Boehler public $time; 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler /** 32*a1a3b679SAndreas Boehler * Constructor 33*a1a3b679SAndreas Boehler * 34*a1a3b679SAndreas Boehler * @param int|DateTime $time 35*a1a3b679SAndreas Boehler */ 36*a1a3b679SAndreas Boehler function __construct($time) { 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler if ($time instanceof DateTime) { 39*a1a3b679SAndreas Boehler $this->time = clone $time; 40*a1a3b679SAndreas Boehler } else { 41*a1a3b679SAndreas Boehler $this->time = new DateTime('@' . $time); 42*a1a3b679SAndreas Boehler } 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler // Setting timezone to UTC 45*a1a3b679SAndreas Boehler $this->time->setTimezone(new DateTimeZone('UTC')); 46*a1a3b679SAndreas Boehler 47*a1a3b679SAndreas Boehler } 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler /** 50*a1a3b679SAndreas Boehler * getTime 51*a1a3b679SAndreas Boehler * 52*a1a3b679SAndreas Boehler * @return DateTime 53*a1a3b679SAndreas Boehler */ 54*a1a3b679SAndreas Boehler function getTime() { 55*a1a3b679SAndreas Boehler 56*a1a3b679SAndreas Boehler return $this->time; 57*a1a3b679SAndreas Boehler 58*a1a3b679SAndreas Boehler } 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler /** 61*a1a3b679SAndreas Boehler * The serialize method is called during xml writing. 62*a1a3b679SAndreas Boehler * 63*a1a3b679SAndreas Boehler * It should use the $writer argument to encode this object into XML. 64*a1a3b679SAndreas Boehler * 65*a1a3b679SAndreas Boehler * Important note: it is not needed to create the parent element. The 66*a1a3b679SAndreas Boehler * parent element is already created, and we only have to worry about 67*a1a3b679SAndreas Boehler * attributes, child elements and text (if any). 68*a1a3b679SAndreas Boehler * 69*a1a3b679SAndreas Boehler * Important note 2: If you are writing any new elements, you are also 70*a1a3b679SAndreas Boehler * responsible for closing them. 71*a1a3b679SAndreas Boehler * 72*a1a3b679SAndreas Boehler * @param Writer $writer 73*a1a3b679SAndreas Boehler * @return void 74*a1a3b679SAndreas Boehler */ 75*a1a3b679SAndreas Boehler function xmlSerialize(Writer $writer) { 76*a1a3b679SAndreas Boehler 77*a1a3b679SAndreas Boehler $writer->write( 78*a1a3b679SAndreas Boehler HTTP\Util::toHTTPDate($this->time) 79*a1a3b679SAndreas Boehler ); 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler } 82*a1a3b679SAndreas Boehler 83*a1a3b679SAndreas Boehler /** 84*a1a3b679SAndreas Boehler * The deserialize method is called during xml parsing. 85*a1a3b679SAndreas Boehler * 86*a1a3b679SAndreas Boehler * This method is called statictly, this is because in theory this method 87*a1a3b679SAndreas Boehler * may be used as a type of constructor, or factory method. 88*a1a3b679SAndreas Boehler * 89*a1a3b679SAndreas Boehler * Often you want to return an instance of the current class, but you are 90*a1a3b679SAndreas Boehler * free to return other data as well. 91*a1a3b679SAndreas Boehler * 92*a1a3b679SAndreas Boehler * Important note 2: You are responsible for advancing the reader to the 93*a1a3b679SAndreas Boehler * next element. Not doing anything will result in a never-ending loop. 94*a1a3b679SAndreas Boehler * 95*a1a3b679SAndreas Boehler * If you just want to skip parsing for this element altogether, you can 96*a1a3b679SAndreas Boehler * just call $reader->next(); 97*a1a3b679SAndreas Boehler * 98*a1a3b679SAndreas Boehler * $reader->parseInnerTree() will parse the entire sub-tree, and advance to 99*a1a3b679SAndreas Boehler * the next element. 100*a1a3b679SAndreas Boehler * 101*a1a3b679SAndreas Boehler * @param Reader $reader 102*a1a3b679SAndreas Boehler * @return mixed 103*a1a3b679SAndreas Boehler */ 104*a1a3b679SAndreas Boehler static function xmlDeserialize(Reader $reader) { 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler return 107*a1a3b679SAndreas Boehler new self(new DateTime($reader->parseInnerTree())); 108*a1a3b679SAndreas Boehler 109*a1a3b679SAndreas Boehler } 110*a1a3b679SAndreas Boehler} 111