/** * @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()); } }
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)); }
/** * @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(); }