示例#1
0
 /**
  * Returns a link for a file
  *
  * @param  File   $file
  * @return string Link
  */
 protected function getBaseLink(File $file)
 {
     $folder = $this->folderRepository->find($file->getFolderId());
     $beautifurl = explode('/', $folder->getUrl());
     $beautifurl = array_filter($beautifurl, function ($beautifurl) {
         return (bool) $beautifurl;
     });
     $beautifurl = array_map(function ($fragment) {
         return $this->slugifier->slugify($fragment);
     }, $beautifurl);
     $beautifurl[] = $file->getName();
     $beautifurl = implode(DIRECTORY_SEPARATOR, $beautifurl);
     return $beautifurl;
 }
示例#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;
 }
 /**
  * @test
  */
 public function updates()
 {
     $root = $this->op->findRoot();
     $folder = Folder::create(['name' => 'tussi', 'parent_id' => $root->getId()]);
     $folder2 = $this->op->create($folder);
     $this->assertSame($folder, $folder2);
     $this->op->update($folder);
     $this->ed->dispatch(Events::FOLDER_AFTER_UPDATE, Argument::type('Xi\\Filelib\\Event\\FolderEvent'))->shouldHaveBeenCalledTimes(1);
 }
 /**
  * @test
  */
 public function isFileReadableByAnonymousShouldDelegateToFolderWhenAclIsFolderBased()
 {
     $file = File::create(array('id' => 1, 'folder_id' => 1));
     $folder = Folder::create(array('id' => 1));
     $this->foop->expects($this->once())->method('find')->with($this->equalTo(1))->will($this->returnValue($folder));
     $acl = $this->getMockBuilder('Xi\\Filelib\\Authorization\\Adapter\\SymfonyAuthorizationAdapter')->setConstructorArgs(array($this->context, $this->aclProvider, true))->setMethods(array('isFolderReadableByAnonymous'))->getMock();
     $acl->attachTo($this->filelib);
     $acl->expects($this->once())->method('isFolderReadableByAnonymous')->with($this->equalTo($folder));
     $this->assertTrue($acl->isFolderBased());
     $ret = $acl->isFileReadableByAnonymous($file);
 }
 /**
  * Returns a file's folder
  *
  * @param  File   $file
  * @return Folder
  */
 private function getFilesFolder(File $file)
 {
     return $this->folderRepository->find($file->getFolderId());
 }