作者:jacko97
项目:pim-community-de
function it_throws_an_exception_when_the_file_can_not_be_read_on_the_filesystem(FileInterface $file, FilesystemInterface $filesystem)
{
$file->getKey()->willReturn('path/to/file.txt');
$filesystem->has('path/to/file.txt')->willReturn(true);
$filesystem->readStream('path/to/file.txt')->willReturn(false);
$this->shouldThrow(new FileTransferException('Unable to fetch the file "path/to/file.txt" from the filesystem.'))->during('fetch', [$file, $filesystem]);
}
作者:cass-projec
项目:cas
private function touchDir(FilesystemInterface $fs, string $entityId, string $collectionUID, string $imageId) : string
{
$resultPath = sprintf('%s/%s/%s', $entityId, $collectionUID, $imageId);
if (!$fs->has($resultPath)) {
$fs->createDir($resultPath);
}
return $resultPath;
}
作者:whisma
项目:glid
/**
* Create response.
* @param FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
* @return Response Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $this->streamCallback->__invoke($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$cacheControl = 'max-age=31536000, public';
$expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
}
作者:hannesko
项目:yaysond
/**
* @throws FileNotFoundException If fname does not exist in filesystem
*/
public function __construct(string $fname, FilesystemInterface $fsystem, DecoderInterface $decoder = null)
{
if (!$fsystem->has($fname)) {
throw new FileNotFoundException("Unable to read file {$fname}");
}
$this->fname = $fname;
$this->fsystem = $fsystem;
$this->decoder = $decoder ?: $this->guessDecoder();
$this->reset();
}
作者:ValentinGo
项目:trakt-api-wrappe
/**
* @param ReflectionClass $reflection
* @param FilesystemInterface $filesystem
* @param null $name
*/
public function __construct(ReflectionClass $reflection, FilesystemInterface $filesystem, $name = null)
{
$this->reflection = $reflection;
$this->template = $filesystem->read("/Console/stubs/method.stub");
$this->name = $name;
$this->classParameters = $this->getClassParameters();
$this->uses = $this->getUsages();
$this->methodParameterNames = $this->getMethodParameters();
$this->requestParameters = $this->getRequestParameters();
}
作者:balee
项目:storage-flysyste
/**
* @param FilesystemInterface $filesystem
* @param string $fileName
*
* @throws StorageException
*/
public function __construct(FilesystemInterface $filesystem, $fileName = self::DEFAULT_FILENAME)
{
if (!$filesystem->has($fileName)) {
$filesystem->write($fileName, '');
}
$handler = $filesystem->get($fileName);
if (!$handler->isFile()) {
throw new StorageException(sprintf('Expected path "%s" to be a file but its a "%s".', $handler->getPath(), $handler->getType()));
}
$this->file = $handler;
}
作者:repa
项目:flysystem-syn
protected function getPaths(FilesystemInterface $filesystem, $skipDirs)
{
$paths = [];
foreach ($filesystem->listContents($this->dir, true) as $path) {
if ($skipDirs && $path['type'] === 'dir') {
continue;
}
$paths[$path['path']] = $path;
}
ksort($paths);
return $paths;
}
作者:adma
项目:cakephp-glid
/**
* Create response.
*
* @param \League\Flysystem\FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
*
* @return \Psr\Http\Message\ResponseInterface Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = new Stream($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
if ($contentType === false) {
throw new FilesystemException('Unable to determine the image content type.');
}
if ($contentLength === false) {
throw new FilesystemException('Unable to determine the image content length.');
}
return (new Response())->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength);
}
作者:jacko97
项目:pim-community-de
/**
* {@inheritdoc}
*/
public function fetch(FileInterface $file, FilesystemInterface $filesystem)
{
if (!$filesystem->has($file->getKey())) {
throw new \LogicException(sprintf('The file "%s" is not present on the filesystem.', $file->getKey()));
}
$localPathname = tempnam(sys_get_temp_dir(), 'raw_file_fetcher_');
if (false === ($stream = $filesystem->readStream($file->getKey()))) {
throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $file->getKey()));
}
if (false === file_put_contents($localPathname, $stream)) {
throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $file->getKey()));
}
return new \SplFileInfo($localPathname);
}
作者:kivagan
项目:staticus-cor
protected function deleteFile($filePath)
{
// If file is already gone somewhere, it is OK for us
if ($this->filesystem->has($filePath) && !$this->filesystem->delete($filePath)) {
throw new CommandErrorException('The file cannot be removed: ' . $filePath);
}
}
作者:roelvanduijnhove
项目:backup-email-chec
/**
* Return string error message if not found to be correct
*
* @return string|bool
*/
public function assertBackups($today)
{
$day = $today;
$sizes = [];
for ($i = 0; $i < 2; $i++) {
$expected = 's77_mail_' . $day->format('Y-m-d') . '.tar.gz';
try {
$size = $this->filesystem->getSize($expected);
if ($size === false) {
return "Kan bestandsgrootte niet ophalen van '{$expected}'";
}
$sizes[] = $size;
if ($size < 3.4 * 1000 * 1000 * 1000) {
$humanSize = $size / 1000 / 1000;
return "Email backup lijkt te klein ({$humanSize} MB)";
}
} catch (\League\Flysystem\FileNotFoundException $e) {
return "Kon email backup niet vinden: '{$expected}'";
}
$day = $day->sub(new \DateInterval('P1D'));
}
if (count(array_unique($sizes)) === 1) {
return "Laatste twee e-mail backups zijn even groot.";
}
return true;
}
作者:dragosprotun
项目:stc-cor
/**
* {@inheritdoc}
*/
public function toFile(Workout $workout, string $outputFile) : bool
{
$return = $this->filesystem->put($outputFile, $this->toString($workout));
if ($return !== true) {
throw new Exception(sprintf('Could not write to %s', $outputFile));
}
return true;
}
作者:roelvanduijnhove
项目:backup-email-chec
public function testLastBackupsIdentical()
{
$meta = $this->getMeta(123123123123.0);
$this->fs->getSize('s77_mail_2015-04-22.tar.gz')->willReturn($meta);
$this->fs->getSize('s77_mail_2015-04-21.tar.gz')->willReturn($meta);
$result = $this->assert->assertBackups(new \DateTime('2015-04-22'));
$this->assertEquals("Laatste twee e-mail backups zijn even groot.", $result);
}
作者:Jenkosam
项目:ezpublish-kerne
public function getResource($spiBinaryFileId)
{
try {
return $this->filesystem->readStream($spiBinaryFileId);
} catch (FlysystemNotFoundException $e) {
throw new BinaryFileNotFoundException($spiBinaryFileId, $e);
}
}
作者:brad-jone
项目:pp
/** @inheritdoc */
public function generate(array $replacements, $autoloader)
{
ReflectionEngine::init(new Locator($autoloader));
foreach ($replacements as $replacement) {
$fullPath = $this->vendorDir . '/' . $replacement['package'] . '/proxy/' . str_replace('\\', '/', $replacement['originalFullyQualifiedType']) . ".php";
$this->filesystem->put($fullPath, $this->buildClass($replacement));
}
}
作者:svyck
项目:sv-image
/**
* {@inheritdoc}
*/
public function delete($path)
{
try {
return $this->filesystem->delete($path);
} catch (FileNotFoundException $exception) {
return false;
}
}
作者:AltThre
项目:Storag
/**
* Delete an item from the storage if it exists.
*
* @param string $key
*
* @return void
*/
public function delete($key)
{
try {
$this->flysystem->delete($key);
} catch (FileNotFoundException $e) {
//
}
}
作者:graunda
项目:LiipImagineBundl
/**
* {@inheritdoc}
*/
public function find($path)
{
if ($this->filesystem->has($path) === false) {
throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
}
$mimeType = $this->filesystem->getMimetype($path);
return new Binary($this->filesystem->read($path), $mimeType, $this->extensionGuesser->guess($mimeType));
}
作者:dragosprotun
项目:stc-cor
/**
* {@inheritdoc}
*/
public function fromFile($file) : Workout
{
$content = $this->filesystem->read($file);
if ($content === false) {
throw new UnreadableFileException();
}
return $this->fromString($content);
}
作者:aleksab
项目:bol
protected function adapterType()
{
if ($this->filesystem instanceof Filesystem) {
$reflect = new \ReflectionClass($this->filesystem->getAdapter());
return $reflect->getShortName();
}
return 'Unknown';
}