本文整理汇总了PHP中League\Flysystem\Filesystem::readStream方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::readStream方法的具体用法?PHP Filesystem::readStream怎么用?PHP Filesystem::readStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::readStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadAttachment
/**
* @param $filePath
* @param $toBeDownloadedFileName
*
* @return int
*/
public function downloadAttachment($filePath, $toBeDownloadedFileName = '')
{
if (!is_readable($this->currentPath . $filePath)) {
$this->setError(self::ERROR_ATTACHMENT_FILE_DOES_NOT_EXIST);
}
if (empty($toBeDownloadedFileName)) {
$toBeDownloadedFileName = basename($filePath);
if (empty($toBeDownloadedFileName)) {
$this->setError(self::ERROR_ATTACHMENT_DOES_NOT_EXIST);
}
}
if ($this->hasError()) {
return $this->errors;
}
$this->setHeadersForAttachmentDownload($toBeDownloadedFileName);
if ($this->fileSystem->getSize($filePath) > DirectoryStructure::FS_DOWNLOAD_STREAM_AFTER_SIZE) {
header('Content-Length: ' . $this->fileSystem->getSize($filePath));
$stream = $this->fileSystem->readStream($filePath);
while (!feof($stream)) {
print fgets($stream, 1024);
flush();
}
fclose($stream);
exit;
} else {
ob_start();
ob_start("ob_gzhandler");
echo $this->fileSystem->get($filePath)->read();
ob_end_flush();
$gzippedContent = ob_get_contents();
// store gzipped content to get size
header('Content-Length: ' . strlen($gzippedContent));
ob_end_flush();
exit;
}
}
示例2: getArchive
/**
* {@inheritdoc}
*/
public function getArchive(JobExecution $jobExecution, $key)
{
$archives = $this->getArchives($jobExecution);
if (!isset($archives[$key])) {
throw new \InvalidArgumentException(sprintf('Key "%s" does not exist', $key));
}
return $this->filesystem->readStream($archives[$key]);
}
示例3: testReadStream
public function testReadStream()
{
$adapter = Mockery::mock('League\\Flysystem\\AdapterInterface');
$adapter->shouldReceive('has')->andReturn(true);
$adapter->shouldReceive('readStream')->twice()->andReturn(array('stream' => 'this result'), false);
$filesystem = new Filesystem($adapter);
$this->assertEquals('this result', $filesystem->readStream('file.txt'));
$this->assertFalse($filesystem->readStream('other.txt'));
// Another time to hit the cache
$this->assertEquals('this result', $filesystem->readStream('file.txt'));
}
示例4: testReadStream
public function testReadStream()
{
$adapter = Mockery::mock('League\\Flysystem\\AdapterInterface');
$adapter->shouldReceive('has')->andReturn(true);
$stream = tmpfile();
$adapter->shouldReceive('readStream')->times(3)->andReturn(['stream' => $stream], false, false);
$filesystem = new Filesystem($adapter);
$this->assertInternalType('resource', $filesystem->readStream('file.txt'));
$this->assertFalse($filesystem->readStream('other.txt'));
fclose($stream);
$this->assertFalse($filesystem->readStream('other.txt'));
}
示例5:
function it_should_execute_the_transfer_file_command(Filesystem $source, Filesystem $destination)
{
$source->readStream('source')->willReturn('data');
$destination->writeStream('destination', 'data')->shouldBeCalled();
$this->beConstructedWith($source, 'source', $destination, 'destination');
$this->execute();
}
示例6: testReadStreamFail
public function testReadStreamFail()
{
$path = 'path.txt';
$this->prophecy->has($path)->willReturn(true);
$this->prophecy->readStream($path)->willReturn(false);
$response = $this->filesystem->readStream($path);
$this->assertFalse($response);
}
示例7: readStream
/**
* @inheritdoc
*/
public function readStream($path)
{
try {
return $this->fileSystem->readStream($this->getInnerPath($path));
} catch (FileNotFoundException $e) {
throw $this->exceptionWrapper($e, $path);
}
}
示例8: testPushNotExists
public function testPushNotExists()
{
$file = '123-123-123';
$path = sprintf('%s/%s.zip', $this->name, $file);
$this->localFilesystem->readStream($path)->willReturn(false);
$this->remoteFilesystem->putStream($path, Argument::any())->shouldNotBeCalled();
$this->storage->push($file);
}
示例9: push
/**
* {@inheritdoc}
*/
public function push($file)
{
if (!$this->remoteFilesystem) {
throw new RemoteStorageNotConfiguredException();
}
$path = sprintf('%s/%s.zip', $this->name, $file);
if (false === ($stream = $this->localFilesystem->readStream($path)) || $this->remoteFilesystem->has($path)) {
return;
}
$this->remoteFilesystem->putStream($path, $stream);
}
示例10: deployToRemote
/**
* Deploy files to the remote filesystem.
*
* @return void
*/
public function deployToRemote()
{
$local_path = $this->relativeDumpPath();
$files = $this->localAdapter->listContents($local_path);
foreach ($files as $file) {
$contents = $this->localAdapter->readStream($local_path . $file['basename']);
$file_size = $this->localAdapter->getSize($local_path . $file['basename']);
$this->out($this->parseString('Uploading %s (%s)', [$file['basename'], $this->formatBytes($file_size)], 'light_green'));
$this->remoteAdapter->writeStream($local_path . $file['basename'], $contents);
}
}
示例11: fopen
/**
* {@inheritdoc}
*/
public function fopen($path, $mode)
{
$fullPath = $this->buildPath($path);
$useExisting = true;
switch ($mode) {
case 'r':
case 'rb':
try {
return $this->flysystem->readStream($fullPath);
} catch (FileNotFoundException $e) {
return false;
}
case 'w':
case 'w+':
case 'wb':
case 'wb+':
$useExisting = false;
case 'a':
case 'ab':
case 'r+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
//emulate these
if ($useExisting and $this->file_exists($path)) {
if (!$this->isUpdatable($path)) {
return false;
}
$tmpFile = $this->getCachedFile($path);
} else {
if (!$this->isCreatable(dirname($path))) {
return false;
}
$tmpFile = \OCP\Files::tmpFile();
}
$source = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($source, null, null, function () use($tmpFile, $fullPath) {
$this->flysystem->putStream($fullPath, fopen($tmpFile, 'r'));
unlink($tmpFile);
});
}
return false;
}
示例12:
function it_should_unsuccessfully_read_stream_from_remote_file($path, Filesystem $filesystem)
{
$filesystem->readStream($path)->willReturn(false);
$this->readStream($path)->shouldReturn(false);
$filesystem->readStream($path)->shouldBeCalled();
}
示例13: testReadStream
public function testReadStream()
{
$this->assertInternalType('resource', $this->filesystem->readStream('2.txt'));
}
示例14: moveToTrash
/**
* Moves a file from somewhere to the expired trash heap
*
* @param Filesystem $filesystem
* @param string $filename
* @param array $config An optional configuration array
*
* @return bool
*/
protected function moveToTrash(Filesystem $filesystem, $filename, array $config = [])
{
if (config('snapshot.soft-delete', EnterpriseDefaults::SNAPSHOT_SOFT_DELETE)) {
$_trash = InstanceStorage::getTrashMount('expired');
if ($_trash->writeStream($filename, $filesystem->readStream($filename), $config)) {
return $filesystem->delete($filename);
}
// Try and remove any partial file created before failure
try {
$_trash->delete($filename);
} catch (\Exception $_ex) {
// Ignored, this is a cleanup in case of failure...
}
} else {
try {
if ($filesystem->has($filename)) {
return $filesystem->delete($filename);
}
// It's gone
return true;
} catch (\Exception $_ex) {
// Can't delete? not good
return false;
}
}
return false;
}
示例15: execute
/**
* @throws \InvalidArgumentException
*/
public function execute()
{
$this->destinationFilesystem->writeStream($this->destinationPath, $this->sourceFilesystem->readStream($this->sourcePath));
}