示例#1
0
 protected function getDestinationPath(Uri $baseUri, HttpRequest $request)
 {
     if (!$request->hasHeader('Destination')) {
         throw new BadRequestException();
     }
     $dest = $request->getHeader('Destination');
     if (preg_match("'^(?:https?:)?//'i", $dest)) {
         try {
             $uri = new Uri($dest);
         } catch (\Exception $e) {
             throw new BadRequestException($e);
         }
         if (0 !== strpos((string) $uri, rtrim($baseUri, '/') . '/')) {
             throw new WebDavException(WebDav::CODE_BAD_GATEWAY);
         }
         return Uri::decode(substr($uri->getPath(), strlen(rtrim($baseUri->getPath(), '/') . '/')));
     }
     if (preg_match("'^/.*'", $dest)) {
         $path = '/' . trim($dest, '/');
         $base = rtrim('/' . $baseUri->getPath(), '/') . '/';
         if (0 !== strpos($path, $base)) {
             throw new WebDavException(WebDav::CODE_BAD_GATEWAY);
         }
         return Uri::decode(substr($path, strlen($base)));
     }
     throw new BadRequestException();
 }
示例#2
0
 public static function fromString($value)
 {
     $index = strpos($value, '=');
     $name = substr($value, 0, $index);
     $index2 = strpos($value, ';', $index + 1);
     if ($index2 === false) {
         return new static($name);
     }
     $val = substr($value, $index + 1, $index2 - $index - 1);
     return new static($name, Uri::decode($val), Directives::parseDirectives(substr($value, $index2 + 1)));
 }
示例#3
0
 public function getResourcePath(Uri $baseUri, Uri $requestUri)
 {
     if ($this->path === '') {
         return ltrim(substr($requestUri->getPath(false), strlen($baseUri->getPath(false))), '/');
     }
     if (preg_match("'^/+'", $this->path)) {
         return ltrim($this->path, '/');
     }
     if (preg_match("'^https?://'", $this->path)) {
         if (0 !== strpos($this->path, $baseUri)) {
             throw new \InvalidArgumentException(sprintf('URI does not refer to this WebDAV share: "%s"', $this->path));
         }
         return Uri::decode(trim(substr($this->path, strlen($baseUri)), '/'));
     }
     throw new \InvalidArgumentException(sprintf('Unprocessable tag in list: "%s"', $this->path));
 }