Ejemplo n.º 1
0
 public function evaluateCondition(ResourceInterface $resource = NULL)
 {
     if ($this->not) {
         if ($resource === NULL || $resource->isCollection()) {
             return true;
         }
         return (string) $this->etag !== (string) $resource->getEtag();
     }
     if ($resource === NULL || $resource->isCollection()) {
         return false;
     }
     return (string) $this->etag === (string) $resource->getEtag();
 }
Ejemplo n.º 2
0
 public function streamResourceProperties(ResourceInterface $resource, XmlStreamWriterInterface $xml, $baseUri)
 {
     $xml->startElement(WebDav::NS_DAV, 'response');
     $xml->writeElement(WebDav::NS_DAV, 'href', $baseUri . Uri::encode($resource->getPath()));
     $xml->startElement(WebDav::NS_DAV, 'propstat');
     $xml->startElement(WebDav::NS_DAV, 'prop');
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'displayname')) {
         $name = $resource->getName();
         if ($name != '') {
             $xml->writeElement(WebDav::NS_DAV, 'displayname', $resource->getName());
         }
     }
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'iscollection')) {
         $xml->writeElement(WebDav::NS_DAV, 'iscollection', $resource->isCollection() ? '1' : '0');
     }
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'resourcetype')) {
         $xml->startElement(WebDav::NS_DAV, 'resourcetype');
         if ($resource->isCollection()) {
             $xml->writeElement(WebDav::NS_DAV, 'collection');
         }
         $xml->endElement();
         // D:resourcetype
     }
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'getcontenttype')) {
         $xml->writeElement(WebDav::NS_DAV, 'getcontenttype', $resource->getMediaType());
     }
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'creationdate')) {
         $xml->writeElement(WebDav::NS_DAV, 'creationdate', $resource->getCreated()->setTimezone($this->utc)->format(WebDav::DATE_FORMAT_TZ));
     }
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'getlastmodified')) {
         $xml->writeElement(WebDav::NS_DAV, 'getlastmodified', $resource->getLastModified()->setTimezone($this->utc)->format(WebDav::DATE_FORMAT_RFC1123));
     }
     if (!$resource->isCollection()) {
         if ($this->propfind->hasProperty(WebDav::NS_DAV, 'getcontentlength')) {
             $xml->writeElement(WebDav::NS_DAV, 'getcontentlength', $resource->getSize());
         }
         if ($this->propfind->hasProperty(WebDav::NS_DAV, 'getetag')) {
             $xml->writeElement(WebDav::NS_DAV, 'getetag', $resource->getEtag());
         }
     } else {
         if ($this->propfind->hasProperty(WebDav::NS_DAV, 'getcontentlength')) {
             $xml->writeElement(WebDav::NS_DAV, 'getcontentlength', 0);
         }
     }
     if ($this->propfind->hasProperty(WebDav::NS_DAV, 'supported-method-set', false)) {
         $xml->startElement(WebDav::NS_DAV, 'supported-method-set');
         $event = new PopulateOptionsEvent($resource);
         $this->dispatcher->notify($event);
         foreach ($event->allow as $method) {
             $xml->startElement(WebDav::NS_DAV, 'supported-method');
             $xml->writeAttribute('', 'name', $method);
             $xml->endElement();
             // D:supported-method
         }
         $xml->endElement();
         // D:supported-method-set
     }
     $this->dispatcher->notify(new SerializePropertiesEvent($resource, $this->baseUri, $this->propfind, $xml));
     $xml->endElement();
     // D:prop
     $xml->writeElement(WebDav::NS_DAV, 'status', 'HTTP/1.1 200 OK');
     $xml->endElement();
     // D:propstat
     $xml->endElement();
     // D:response
     $xml->flush();
 }