本文整理汇总了PHP中League\Flysystem\FilesystemInterface::readStream方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::readStream方法的具体用法?PHP FilesystemInterface::readStream怎么用?PHP FilesystemInterface::readStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::readStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create the response.
*
* @param \League\Flysystem\FilesystemInterface $cache The cache file system.
* @param string $path The cached file path.
*
* @return \Cake\Network\Response The response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $cache->readStream($path);
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$response = new Response();
$response->type($contentType);
$response->header('Content-Length', $contentLength);
$response->body(function () use($stream) {
rewind($stream);
fpassthru($stream);
fclose($stream);
});
return $response;
}
示例2: getResource
public function getResource($spiBinaryFileId)
{
try {
return $this->filesystem->readStream($spiBinaryFileId);
} catch (FlysystemNotFoundException $e) {
throw new BinaryFileNotFoundException($spiBinaryFileId, $e);
}
}
示例3: setContent
/**
* Set the stream response content.
* @param StreamedResponse $response The response object.
* @return StreamedResponse
*/
public function setContent(StreamedResponse $response)
{
$stream = $this->cache->readStream($this->path);
$response->setCallback(function () use($stream) {
rewind($stream);
fpassthru($stream);
fclose($stream);
});
return $response;
}
示例4: getFileHash
public function getFileHash($path)
{
$stream = $this->filesystem->readStream($path);
if ($stream !== false) {
$context = hash_init(self::HASH_ALGORITHM);
hash_update_stream($context, $stream);
return hash_final($context);
}
return false;
}
示例5: FileTransferException
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]);
}
示例6: open
/**
* @return resource|false
*/
public function open()
{
$file = $this->getConfig(self::FILE_LOC);
if ($this->fileSystem) {
list($stream) = $this->fileSystem->readStream($file);
return $stream;
}
return fopen($file, 'r+');
}
示例7: create
/**
* 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);
}
示例8: getGDHandle
/**
* @return resource
*/
public function getGDHandle()
{
if (!$this->is_image) {
return null;
}
$size = $this->_filesystem->getSize($this->getPath());
$handle = $this->_filesystem->readStream($this->getPath());
return imagecreatefromstring(fread($handle, $size));
}
示例9: outputImage
/**
* Generate and output image.
* @param string $path Image path.
* @param array $params Image manipulation params.
* @throws InvalidArgumentException
*/
public function outputImage($path, array $params)
{
$path = $this->makeImage($path, $params);
header('Content-Type:' . $this->cache->getMimetype($path));
header('Content-Length:' . $this->cache->getSize($path));
header('Cache-Control:' . 'max-age=31536000, public');
header('Expires:' . date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT');
$stream = $this->cache->readStream($path);
rewind($stream);
fpassthru($stream);
fclose($stream);
}
示例10: create
/**
* 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);
}
示例11: fetch
/**
* {@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);
}
示例12: create
/**
* Create response.
* @param FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
* @return ResponseInterface 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';
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 $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
}
示例13: sendContent
/**
* Sends the file.
*/
public function sendContent()
{
if (!$this->isSuccessful()) {
parent::sendContent();
return;
}
if (0 === $this->maxlen) {
return;
}
$out = fopen('php://output', 'wb');
$file = $this->filesystem->readStream($this->file->getPath());
stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
fclose($out);
fclose($file);
}
示例14: fetch
/**
* {@inheritdoc}
*/
public function fetch(FilesystemInterface $filesystem, $fileKey)
{
if (!$filesystem->has($fileKey)) {
throw new \LogicException(sprintf('The file "%s" is not present on the filesystem.', $fileKey));
}
if (false === ($stream = $filesystem->readStream($fileKey))) {
throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey));
}
if (!$this->tmpFilesystem->has(dirname($fileKey))) {
$this->tmpFilesystem->createDir(dirname($fileKey));
}
$localPathname = $this->tmpFilesystem->getAdapter()->getPathPrefix() . $fileKey;
if (false === file_put_contents($localPathname, $stream)) {
throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey));
}
return new \SplFileInfo($localPathname);
}
示例15: fetch
/**
* {@inheritdoc}
*/
public function fetch(FilesystemInterface $filesystem, $fileKey, array $options = [])
{
if (!$filesystem->has($fileKey)) {
throw new \LogicException(sprintf('The file "%s" is not present on the filesystem.', $fileKey));
}
if (false === ($stream = $filesystem->readStream($fileKey))) {
throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey));
}
if (!$this->tmpFilesystem->has(dirname($fileKey))) {
$this->tmpFilesystem->createDir(dirname($fileKey));
}
// TODO: we should not get the path prefix like that
// TODO: it should be injected in the constructor
$localPathname = $this->tmpFilesystem->getAdapter()->getPathPrefix() . $fileKey;
if (false === file_put_contents($localPathname, $stream)) {
throw new FileTransferException(sprintf('Unable to fetch the file "%s" from the filesystem.', $fileKey));
}
return new \SplFileInfo($localPathname);
}