/** * @param File $file * @param Version $version * @param VersionProvider $versionProvider * @param Linker $linker * @return bool */ public function publish(File $file, Version $version, VersionProvider $versionProvider, Linker $linker) { $path = $linker->getLink($file, $version, $versionProvider->getExtension($file, $version)); $tmp = $this->storage->retrieveVersion($versionProvider->getApplicableVersionable($file), $version); if ($this->filesystem->has($path)) { return false; } $this->filesystem->write($path, file_get_contents($tmp), ['visibility' => AdapterInterface::VISIBILITY_PUBLIC]); return true; }
public function publish(File $file, Version $version, VersionProvider $versionProvider, Linker $linker) { $link = $this->getPublicRoot() . '/' . $linker->getLink($file, $version, $versionProvider->getExtension($file, $version)); if (!is_file($link)) { $path = dirname($link); if (!is_dir($path)) { mkdir($path, $this->getDirectoryPermission(), true); } $tmp = $this->storage->retrieveVersion($versionProvider->getApplicableVersionable($file), $version); copy($tmp, $link); chmod($link, $this->getFilePermission()); } }
/** * @test */ public function createProvidedVersionsShouldCreateVersions() { $retrievedPath = ROOT_TESTS . '/data/self-lussing-manatee.jpg'; $file = File::create(array('id' => 1, 'resource' => Resource::create())); $this->storage->expects($this->exactly(2))->method('retrieve')->with($this->isInstanceOf('Xi\\Filelib\\Resource\\Resource'))->will($this->returnValue($retrievedPath)); $ed = $this->getMockedEventDispatcher(); $pm = $this->getMockedProfileManager(array('xooxer')); $filelib = $this->getMockedFilelib(null, array('storage' => $this->storage, 'pm' => $pm, 'ed' => $ed)); $this->plugin->attachTo($filelib); $ret = $this->plugin->createAllTemporaryVersions($file); $this->assertInternalType('array', $ret); foreach ($ret as $version => $tmp) { $this->assertRegExp('#^' . ROOT_TESTS . '/data/temp#', $tmp); } }
public function publish(File $file, Version $version, VersionProvider $versionProvider, Linker $linker) { $link = $this->getPublicRoot() . '/' . $linker->getLink($file, $version, $versionProvider->getExtension($file, $version)); if (!is_link($link)) { $path = dirname($link); if (!is_dir($path)) { mkdir($path, $this->getDirectoryPermission(), true); } if ($this->getRelativePathToRoot()) { $path2 = substr($path, strlen($this->getPublicRoot()) + 1); // If the link goes to the root dir, $path2 is false and fuxors the depth without a check. if ($path2 === false) { $depth = 0; } else { $depth = sizeof(explode(DIRECTORY_SEPARATOR, $path2)); } $fp = $this->getRelativePathToVersion($file, $version, $versionProvider, $depth); // Relative linking requires some movin'n groovin. $oldCwd = getcwd(); chdir($path); symlink($fp, $link); chdir($oldCwd); } else { symlink($this->storage->retrieveVersion($versionProvider->getApplicableVersionable($file), $version), $link); } } }
/** * @test */ public function retrieveVersionExitsEarlyWithCache() { $resource = Resource::create(); $version = Version::get('lusso'); $retrieved = new Retrieved('lus', false); $this->adapter->expects($this->never())->method('retrieveVersion'); $this->adapter->expects($this->never())->method('versionExists'); $this->cache->expects($this->at(0))->method('getVersion')->with($resource, $version)->will($this->returnValue($retrieved)); $this->assertEquals('lus', $this->storage->retrieveVersion($resource, $version)); }
/** * Handles impostor's resource * * @param File $file */ private function handleImpostorResource(File $file) { $oldResource = $file->getResource(); if ($oldResource->isExclusive()) { $retrieved = $this->storage->retrieve($oldResource); $resource = Resource::create(); $resource->setDateCreated(new DateTime()); $resource->setHash($oldResource->getHash()); $resource->setSize($oldResource->getSize()); $resource->setMimetype($oldResource->getMimetype()); $this->resourceRepository->create($resource, $retrieved); $file->setResource($resource); } }
/** * Creates a resource * * @param Resource $resource * @param string $path */ public function create(Resource $resource, $path) { $event = new ResourceEvent($resource); $this->eventDispatcher->dispatch(Events::RESOURCE_BEFORE_CREATE, $event); $resource->setUuid(Uuid::uuid4()->toString()); $this->backend->createResource($resource); // @todo: this has to be correctly robustified. try { $this->storage->store($resource, $path); } catch (\Exception $e) { $this->backend->deleteResource($resource); throw $e; } $event = new ResourceEvent($resource); $this->eventDispatcher->dispatch(Events::RESOURCE_AFTER_CREATE, $event); return $resource; }
public function __construct($storageAdapter, $backendAdapter, EventDispatcherInterface $eventDispatcher = null, $tempDir = null) { if (!$eventDispatcher) { $eventDispatcher = new EventDispatcher(); } if (!$tempDir) { $tempDir = sys_get_temp_dir(); } if (!$tempDir instanceof TemporaryFileManager) { $tempDir = new TemporaryFileManager($tempDir); } $this->temporaryFileManager = $tempDir; $this->backendAdapter = $backendAdapter; $this->eventDispatcher = $eventDispatcher; $this->profileManager = new ProfileManager($this->eventDispatcher); $this->pluginManager = new PluginManager($this); $this->backend = new Backend($this->getEventDispatcher(), $this->backendAdapter); $this->storage = new Storage($storageAdapter); $this->storage->attachTo($this); $this->addProfile(new FileProfile('default')); }
/** * @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); }
/** * Returns the mimetype of a version provided by this plugin via retrieving and inspecting. * More specific plugins should override this for performance. * * @param File $file * @param Version $version * @return string */ public function getMimeType(File $file, Version $version) { $retrieved = $this->storage->retrieveVersion($this->getApplicableVersionable($file), $version); $fileObj = new FileObject($retrieved); return $fileObj->getMimeType(); }