Example #1
0
 /**
  * @param  File       $file
  * @param  FileUpload $upload
  * @return Resource
  */
 public function findResourceForUpload(File $file, FileUpload $upload)
 {
     $file = clone $file;
     $hash = sha1_file($upload->getRealPath());
     $profileObj = $this->profiles->getProfile($file->getProfile());
     $finder = new ResourceFinder(array('hash' => $hash));
     $resources = $this->backend->findByFinder($finder);
     if ($resources) {
         foreach ($resources as $resource) {
             if (!$resource->isExclusive()) {
                 $file->setResource($resource);
                 if (!$profileObj->isSharedResourceAllowed($file)) {
                     $file->unsetResource();
                 }
                 break;
             }
         }
     }
     if (!$file->getResource()) {
         $resource = Resource::create();
         $resource->setDateCreated(new DateTime());
         $resource->setHash($hash);
         $resource->setSize($upload->getSize());
         $resource->setMimetype($upload->getMimeType());
         $file->setResource($resource);
         if (!$profileObj->isSharedResourceAllowed($file)) {
             $resource->setExclusive(true);
         }
         $this->create($resource, $upload->getRealPath());
         $file->setResource($resource);
     }
     return $file->getResource();
 }
Example #2
0
 /**
  * Uploads a file
  *
  * @param  mixed            $upload Uploadable, path or object
  * @param  Folder           $folder
  * @return File
  * @throws FilelibException
  */
 public function upload($upload, Folder $folder = null, $profile = 'default')
 {
     if (!$upload instanceof FileUpload) {
         $upload = new FileUpload($upload);
     }
     if (!$folder) {
         $folder = $this->folderRepository->findRoot();
     }
     $event = new FolderEvent($folder);
     $this->eventDispatcher->dispatch(Events::FOLDER_BEFORE_WRITE_TO, $event);
     $profileObj = $this->profiles->getProfile($profile);
     $event = new FileUploadEvent($upload, $folder, $profileObj);
     $this->eventDispatcher->dispatch(Events::FILE_UPLOAD, $event);
     $upload = $event->getFileUpload();
     $file = File::create(array('folder_id' => $folder->getId(), 'name' => $upload->getUploadFilename(), 'profile' => $profile, 'date_created' => $upload->getDateUploaded(), 'uuid' => Uuid::uuid4()->toString()));
     $file->setStatus(File::STATUS_RAW);
     $resource = $this->resourceRepository->findResourceForUpload($file, $upload);
     $file->setResource($resource);
     $event = new FileEvent($file);
     $this->eventDispatcher->dispatch(Events::FILE_BEFORE_CREATE, $event);
     $this->backend->createFile($file, $folder);
     $event = new FileEvent($file);
     $this->eventDispatcher->dispatch(Events::FILE_AFTER_CREATE, $event);
     return $file;
 }
Example #3
0
 /**
  * @param File $file
  * @param Version $version
  * @return string
  */
 private function retrieve(File $file, Version $version)
 {
     return $this->storage->retrieveVersion($this->profiles->getVersionProvider($file, $version)->getApplicableVersionable($file), $version);
 }
Example #4
0
 /**
  * @param File $file
  * @param Version $version
  * @return VersionProvider
  */
 protected function getVersionProvider(File $file, Version $version)
 {
     return $this->profiles->getVersionProvider($file, $version);
 }
Example #5
0
 /**
  * @test
  */
 public function getProfileShouldFailWhenProfileDoesNotExist()
 {
     $this->setExpectedException('Xi\\Filelib\\InvalidArgumentException');
     $prof = $this->manager->getProfile('xooxer');
 }