/**
  * @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
 /**
  * Validates filename for files and folders
  * @param File $file
  * @param string $typeName
  */
 public function validate(File $file, $typeName, $sourceFilePath = null)
 {
     $name = $file->getFileName();
     $fileNameHelper = new Helpers\FileNameValidationHelper();
     $result = $fileNameHelper->validate($name);
     if (!$result) {
         $message = $fileNameHelper->getErrorMessage();
         throw new Exception\UploadFilterException(self::EXCEPTION_MESSAGE_KEY, $message);
     }
 }
 /**
  * Shared validation function
  * @param FileAbstraction $file
  */
 public function validate(FileAbstraction $entity, $typeName, $sourceFilePath = null)
 {
     $siblings = $entity->getSiblings();
     $creatingFilename = $entity->getFileName();
     foreach ($siblings as $record) {
         /* @var $record File */
         if (!$record->equals($entity)) {
             $recordName = $record->getFileName();
             $creatingFilename = mb_strtolower($creatingFilename);
             $recordName = mb_strtolower($recordName);
             if ($creatingFilename == $recordName) {
                 $message = $typeName . ' with this name already exists.';
                 throw new Exception\DuplicateFileNameException(self::EXCEPTION_MESSAGE_KEY, $message);
             }
         }
     }
 }