Ejemplo n.º 1
0
 /**
  * Returns the url for file
  * By default absolute path to file is returned
  * Otherwise when $options array contain key `relative` set as true, relative path will be returned
  *
  * @param $key
  * @param array $options
  * @return mixed
  */
 public function getUrl($key, array $options = [])
 {
     $absolutePathPattern = ':protocol://:username@:host:pwd/:directory/:file';
     $protocol = $this->ssl ? 'ftps' : 'ftp';
     $pwd = ftp_pwd($this->connection);
     $url = strtr($absolutePathPattern, [':protocol' => $protocol, ':username' => $this->username, ':host' => $this->host, ':pwd' => $pwd, ':directory' => $this->directory, ':file' => $key]);
     if (isset($options['relative']) && $options['relative']) {
         $relativePathPattern = ':pwd/:directory/:file';
         $url = strtr($relativePathPattern, [':pwd' => $pwd, ':directory' => $this->directory, ':file' => $key]);
     }
     return Path::normalize($url);
 }
Ejemplo n.º 2
0
 /**
  * Normalizes the given path
  *
  * @param string $path
  *
  * @return string
  */
 protected function normalizePath($path)
 {
     $path = Util\Path::normalize($path);
     if (0 !== strpos($path, $this->directory)) {
         throw new \OutOfBoundsException(sprintf('The path "%s" is out of the filesystem.', $path));
     }
     return $path;
 }
Ejemplo n.º 3
0
 /**
  * Normalizes the given path
  *
  * @param  string $path
  *
  * @return string
  */
 public function normalizePath($path)
 {
     return Util\Path::normalize($path);
 }