/**
  * @param FileAbstraction $file
  * @return string
  */
 protected function generateWebPath(FileAbstraction $file)
 {
     if ($file->isPublic()) {
         $externalUrlBase = $this->fileStorage->getExternalUrlBase();
         if (!empty($externalUrlBase)) {
             $path = $externalUrlBase . DIRECTORY_SEPARATOR;
         } else {
             $path = '/' . str_replace(SUPRA_WEBROOT_PATH, '', $this->fileStorage->getExternalPath());
         }
         // Fix backslash on Windows
         $path = str_replace(array('//', "\\"), '/', $path);
         // get file dir
         $pathNodes = $file->getAncestors(0, false);
         $pathNodes = array_reverse($pathNodes);
         foreach ($pathNodes as $pathNode) {
             /* @var $pathNode Folder */
             $path .= $pathNode->getFileName() . '/';
         }
         // Encode the filename URL part
         $path .= $file->getFileName();
         $transformedPath = $this->pathTransformer->transformWebPath($path);
         $pathParts = explode('/', $transformedPath);
         $pathParts = array_map('rawurlencode', $pathParts);
         return implode('/', $pathParts);
     }
 }
Ejemplo n.º 2
0
 /**
  * Get full file path or its directory (with trailing slash)
  * @param File $file
  * @param boolean $includeFilename
  * @param integer $forcePath Forces external or internal path. Use FILE_INFO_EXTERNAL and FILE_INFO_INTERNAL constants
  * @return string
  */
 public function getFilesystemPath(FileAbstraction $file, $includeFilename = true, $forcePath = null)
 {
     if (!$file instanceof FileAbstraction) {
         throw new Exception\RuntimeException('File or folder entity expected');
     }
     $path = $this->getInternalPath();
     if ($forcePath != self::FILE_INFO_INTERNAL) {
         if ($file->isPublic() || $forcePath == self::FILE_INFO_EXTERNAL) {
             $path = $this->getExternalPath();
         }
     }
     $path .= $file->getPath(DIRECTORY_SEPARATOR, $includeFilename);
     if (!$includeFilename) {
         $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     }
     return $path;
 }