本文整理汇总了PHP中League\Flysystem\Filesystem::writeStream方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::writeStream方法的具体用法?PHP Filesystem::writeStream怎么用?PHP Filesystem::writeStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::writeStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveFile
/**
* {@inheritdoc}
*/
public function saveFile(UploadedFile $uploadedFile, $fileName)
{
$stream = fopen($uploadedFile->getRealPath(), 'r+');
$result = $this->filesystem->writeStream($this->getMediaBasePath() . '/' . $fileName . '.' . $uploadedFile->guessClientExtension(), $stream);
fclose($stream);
return $result;
}
示例2: writeStream
public function writeStream($path, $resource)
{
try {
return $this->filesystem->writeStream($path, $resource);
} catch (FileExistsException $exception) {
return $this->filesystem->updateStream($path, $resource);
}
}
示例3: testWriteStream
/**
* 1.txt
* 2.txt.
*/
public function testWriteStream()
{
$stream = tmpfile();
fwrite($stream, 'OSS text');
rewind($stream);
$this->assertTrue($this->filesystem->writeStream('2.txt', $stream));
fclose($stream);
}
示例4:
function it_should_successfully_update_stream($path, Filesystem $filesystem)
{
$filesystem->writeStream($path, 'resource2')->willThrow('League\\Flysystem\\FileExistsException');
$filesystem->updateStream($path, 'resource2')->willReturn(true);
$this->writeStream($path, 'resource2');
$filesystem->writeStream($path, 'resource2')->shouldBeCalled();
$filesystem->updateStream($path, 'resource2')->shouldBeCalled();
}
示例5: persist
/**
* {@inheritdoc}
*/
public function persist(File $file) : bool
{
// only write temporary, i.e. not yet persisted files, to backend file storage
if ($file->isTmpFile()) {
// use streams for writing to backend file storage
$stream = fopen($file->getTmpPathname(), 'r+');
return $this->filesystem->writeStream($file->getKey(), $stream);
}
return true;
}
示例6: uploadFile
/**
* @param string $fileName
* @return bool
*/
public function uploadFile($fileName)
{
if (true === $this->fileExists($fileName)) {
$fileStream = $this->openFile($fileName, 'r');
$result = $this->fileSystem->writeStream($this->getFileNameFromPath($fileName), $fileStream);
$this->closeFile($fileStream);
return false !== $result;
}
return false;
}
示例7: store
/**
* @param array $fileList
*/
public function store(array $fileList)
{
foreach ($fileList as $file) {
$this->logger->notice('Storing ' . $file . ' in s3 bucket ' . $this->filesystem->getAdapter()->getBucket());
try {
$stream = fopen($file, 'r');
$this->filesystem->writeStream($this->getStoredFilename($file), $stream, ['visibility' => AdapterInterface::VISIBILITY_PRIVATE]);
} catch (\Exception $e) {
$this->logger->error('Exception while storing ' . $file . ': ' . $e->getMessage());
}
if (isset($stream) && is_resource($stream)) {
fclose($stream);
}
}
}
示例8:
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();
}
示例9: testWriteStreamFail
/**
* @expectedException InvalidArgumentException
*/
public function testWriteStreamFail()
{
$adapter = Mockery::mock('League\\Flysystem\\AdapterInterface');
$adapter->shouldReceive('has')->andReturn(false);
$filesystem = new Filesystem($adapter);
$filesystem->writeStream('file.txt', 'not a resource');
}
示例10: handle
/**
* Saves the file with a unique file name.
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
* @param string $directory what subdirectory to upload the file into
* @return mixed If the Flysystem transfer succeeded, returns the final
* file name used.
*/
public function handle(UploadedFile $file = null, $directory = null)
{
if (null == $file) {
return null;
}
$stream = fopen($file->getRealPath(), 'r+');
$this->fileNameGenerator->setFilename($file->getClientOriginalName());
if (null === $directory) {
$directory = '';
}
do {
$filename = $this->fileNameGenerator->nextName();
} while ($this->flysystem->has($directory . $filename));
// TODO error not being handled
$result = $this->flysystem->writeStream($directory . $filename, $stream);
return $filename;
}
示例11: writeStream
/**
* Write a new file using a stream.
*
* @param string $path The path of the new file.
* @param resource $resource The file handle.
* @param array $config An optional configuration array.
*
* @throws InvalidArgumentException If $resource is not a file handle.
* @throws FileExistsException
*
* @return bool True on success, false on failure.
*/
public function writeStream($path, $resource, array $config = [])
{
$result = parent::writeStream($path, $resource, $config);
if ($result && ($resource = $this->get($path))) {
return $this->dispatch(new SyncFile($resource));
}
return $result;
}
示例12: backup
/**
* {@inheritdoc}
*/
public function backup(Filesystem $source, Filesystem $destination, Database $database, array $parameter)
{
$this->output->writeln(' * <comment>export "' . $parameter['path'] . '" to "export.xml"</comment>');
$tempfile = $this->temporaryFileSystem->createTemporaryFile('jackrabbit');
$stream = fopen($tempfile, 'w+');
$this->export($this->getSession($parameter), $parameter['path'], $stream);
fclose($stream);
$destination->writeStream('export.xml', fopen($tempfile, 'r'));
}
示例13: FileExistsException
function it_throws_an_exception_if_the_file_already_exists_on_the_filesystem($mountManager, $factory, \SplFileInfo $rawFile, Filesystem $fs, FileInfoInterface $fileInfo)
{
$rawFile->getPathname()->willReturn(__FILE__);
$fs->has(Argument::any())->willReturn(true);
$fs->writeStream(Argument::any(), Argument::any())->willThrow(new FileExistsException('The file exists.'));
$mountManager->getFilesystem('destination')->willReturn($fs);
$factory->createFromRawFile($rawFile, 'destination')->willReturn($fileInfo);
$fileInfo->getKey()->willReturn('key-file');
$this->shouldThrow(new FileTransferException(sprintf('Unable to move the file "%s" to the "destination" filesystem.', __FILE__)))->during('store', [$rawFile, 'destination']);
}
示例14: 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);
}
}
示例15: doBackup
/**
* @return mixed
*/
public function doBackup()
{
$date = date('YmdHisO');
$dumpName = trim($this->options->getPath() . $date . '.sql', '/');
switch ($this->dumperOptions->getCompress()) {
case Mysqldump::GZIP:
$dumpName = $dumpName . '.gz';
break;
case Mysqldump::BZIP2:
$dumpName = $dumpName . '.bz2';
break;
}
$tmpFile = tempnam(sys_get_temp_dir(), 'bsb-flysystem-mysql-backup-');
$fileStream = fopen($tmpFile, 'rb');
try {
if (false === $fileStream) {
throw new \RuntimeException("A temp file could not be created");
}
// start dump and backup
$this->dumper->start($tmpFile);
$this->filesystem->writeStream($dumpName, $fileStream);
// write a latest file
if ($this->options->getWriteLatest()) {
$this->filesystem->put($this->options->getPath() . $this->options->getWriteLatest(), pathinfo($dumpName, PATHINFO_BASENAME));
}
if ($this->options->getAutoPrune()) {
$this->pruneStorage();
}
} catch (\Exception $e) {
throw new \RuntimeException($e->getMessage());
} finally {
if (is_resource($fileStream)) {
fclose($fileStream);
}
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
}
return $dumpName;
}