本文整理汇总了PHP中League\Flysystem\Filesystem::putStream方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::putStream方法的具体用法?PHP Filesystem::putStream怎么用?PHP Filesystem::putStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::putStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download
/**
* Downloads a request
*
* @param RequestInterface $request
*
* @return boolean
*/
public function download(RequestInterface $request, $path)
{
$response = $this->httpAdapter->sendRequest($request);
if (!($body = $response->getBody())) {
return false;
}
$stream = $body->detach();
if (is_resource($stream)) {
return $this->filesystem->putStream($path, $stream);
}
return $this->filesystem->put($path, $stream);
}
示例2: generate
public function generate()
{
if (PHP_SAPI != 'cli') {
throw new \Exception("This script only can be used in CLI");
}
$config = $this->config->get('database');
system(sprintf('/usr/bin/mysqldump -u %s -h %s -p%s -r /tmp/phosphorum.sql %s', $config->username, $config->host, $config->password, $config->dbname));
system('bzip2 -f /tmp/phosphorum.sql');
$config = $this->config->get('dropbox');
if (!$config instanceof Config) {
throw new \Exception("Unable to retrieve Dropbox credentials. Please check Forum Configuration");
}
if (!$config->get('appSecret') || !$config->get('accessToken')) {
throw new \Exception("Please provide correct 'appSecret' and 'accessToken' config values");
}
$sourcePath = '/tmp/phosphorum.sql.bz2';
if (!file_exists($sourcePath)) {
throw new \Exception("Backup could not be created");
}
$client = new Client($config->get('accessToken'), $config->get('appSecret'));
$adapter = new DropboxAdapter($client, $config->get('prefix', null));
$filesystem = new Filesystem($adapter);
$dropboxPath = '/phosphorum.sql.bz2';
if ($filesystem->has($dropboxPath)) {
$filesystem->delete($dropboxPath);
}
$fp = fopen($sourcePath, "rb");
$filesystem->putStream($dropboxPath, $fp);
fclose($fp);
@unlink($sourcePath);
}
示例3: putFile
/**
* Write the contents of a file with file path.
*
* @param string $path
* @param string $filePath
* @param array $config
* @return mixed
*/
public function putFile($path, $filePath, array $config = [])
{
$resource = fopen(Yii::getAlias($filePath), 'r');
$result = parent::putStream($path, $resource, $config);
fclose($resource);
return $result;
}
示例4: 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);
}
示例5:
function it_handles_ivory_interface_incompatibility(Filesystem $filesystem, HttpAdapterInterface $httpAdapter, Request $request, Response $response, Stream $stream)
{
$httpAdapter->sendRequest($request)->willReturn($response);
$response->getBody()->willReturn($stream);
$stream->detach()->willReturn('text');
$filesystem->putStream('path/to/file', Argument::type('resource'))->shouldNotBeCalled();
$filesystem->put('path/to/file', 'text')->willReturn(true);
$this->download($request, 'path/to/file')->shouldReturn(true);
}
示例6: testPutUpdateStream
public function testPutUpdateStream()
{
$path = 'path.txt';
$stream = tmpfile();
$this->prophecy->has($path)->willReturn(true);
$this->prophecy->updateStream($path, $stream, $this->config)->willReturn(compact('path'));
$this->assertTrue($this->filesystem->putStream($path, $stream));
fclose($stream);
}
示例7: putStream
/**
* @inheritdoc
*/
public function putStream($path, $resource, array $config = [])
{
$addToIndex = !$this->has($path);
$innerPath = $this->getInnerPath($path);
$return = $this->fileSystem->putStream($innerPath, $resource, $config);
if ($return !== false && $addToIndex) {
$this->invokePlugin("addPathToIndex", [$path, $innerPath], $this);
}
return $return;
}
示例8: 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);
}
示例9: assembleChunks
public function assembleChunks($chunks, $removeChunk, $renameChunk)
{
// the index is only added to be in sync with the filesystem storage
$path = $this->prefix . '/' . $this->unhandledChunk['uuid'] . '/';
$filename = $this->unhandledChunk['index'] . '_' . $this->unhandledChunk['original'];
if (empty($chunks)) {
$target = $filename;
} else {
sort($chunks, SORT_STRING | SORT_FLAG_CASE);
$target = pathinfo($chunks[0], PATHINFO_BASENAME);
}
if ($this->unhandledChunk['index'] === 0) {
// if it's the first chunk overwrite the already existing part
// to avoid appending to earlier failed uploads
$handle = fopen($path . '/' . $target, 'w');
} else {
$handle = fopen($path . '/' . $target, 'a');
}
$this->filesystem->putStream($path . $target, $handle);
if ($renameChunk) {
$name = preg_replace('/^(\\d+)_/', '', $target);
/* The name can only match if the same user in the same session is
* trying to upload a file under the same name AND the previous upload failed,
* somewhere between this function, and the cleanup call. If that happened
* the previous file is unaccessible by the user, but if it is not removed
* it will block the user from trying to re-upload it.
*/
if ($this->filesystem->has($path . $name)) {
$this->filesystem->delete($path . $name);
}
$this->filesystem->rename($path . $target, $path . $name);
$target = $name;
}
$uploaded = $this->filesystem->get($path . $target);
if (!$renameChunk) {
return $uploaded;
}
return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
}
示例10: upload
public function upload(FileInterface $file, $name, $path = null)
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
if ($file instanceof FlysystemFile) {
if ($file->getFilesystem() == $this->filesystem) {
$file->getFilesystem()->rename($file->getPath(), $path);
return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
}
$stream = fopen($file->getPathname(), 'r+');
$this->filesystem->putStream($name, $stream);
if (is_resource($stream)) {
fclose($stream);
}
if ($file instanceof FlysystemFile) {
$file->delete();
} else {
$filesystem = new LocalFilesystem();
$filesystem->remove($file->getPathname());
}
return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
示例11: backup
/**
* {@inheritdoc}
*/
public function backup(Filesystem $source, Filesystem $destination, Database $database, array $parameter)
{
$tempFile = $this->temporaryFileSystem->createTemporaryFile('mysql');
$process = new Process($this->getExportCommand($parameter['username'], $parameter['password'], $parameter['database'], $tempFile));
$process->run();
while ($process->isRunning()) {
// waiting for process to finish
}
$handler = fopen($tempFile, 'r');
$destination->putStream('dump.sql', $handler);
fclose($handler);
$this->output->writeln(sprintf(' * <comment>%s</comment>', $this->getExportCommand($parameter['username'], $parameter['password'], $parameter['database'], 'dump.sql', true)));
}
示例12: _save
/**
* @inheritdoc
*/
protected function _save($fp, $dir, $name, $stat)
{
$path = $this->_joinPath($dir, $name);
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
$config = [];
if (isset(self::$mimetypes[$ext])) {
$config['mimetype'] = self::$mimetypes[$ext];
}
if ($this->fs->putStream($path, $fp, $config)) {
return $path;
}
return false;
}
示例13: 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;
}
示例14: testPutStream
/**
* @dataProvider filesystemProvider
*/
public function testPutStream(Filesystem $filesystem, $adapter, $cache)
{
$filesystem->flushCache();
$stream = tmpfile();
fwrite($stream, 'new content');
$this->assertFalse($filesystem->has('new_file.txt'));
$this->assertTrue($filesystem->putStream('new_file.txt', $stream));
fclose($stream);
unset($stream);
$this->assertTrue($filesystem->has('new_file.txt'));
$this->assertEquals('new content', $filesystem->read('new_file.txt'));
$update = tmpfile();
fwrite($update, 'modified content');
$this->assertTrue($filesystem->putStream('new_file.txt', $update));
$filesystem->flushCache();
fclose($update);
$this->assertEquals('modified content', $filesystem->read('new_file.txt'));
}
示例15: archive_backup
function archive_backup($config, $files)
{
info(__FUNCTION__ . ' start...<br />');
$fs = new Filesystem(new ZipArchiveAdapter($config['archive']['target']));
foreach ($files as $remote => $file) {
// info(sprintf('put: %s to %s<br />', $file, $remote));
try {
$fp = fopen($file, 'r+');
$fs->putStream($remote, $fp);
fclose($fp);
} catch (Exception $e) {
info('<span class="color:red">error: ' . $e->getMessage() . '</span>');
info('<span class="color:red">file: ' . $file . '</span>');
}
}
$fs->getAdapter()->getArchive()->close();
info(__FUNCTION__ . ' finished...<br />');
}