本文整理汇总了PHP中League\Flysystem\Util::rewindStream方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::rewindStream方法的具体用法?PHP Util::rewindStream怎么用?PHP Util::rewindStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Util
的用法示例。
在下文中一共展示了Util::rewindStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stream
/**
* Stream fallback delegator.
*
* @param string $path
* @param resource $resource
* @param Config $config
* @param string $fallback
*
* @return mixed fallback result
*/
protected function stream($path, $resource, Config $config, $fallback)
{
Util::rewindStream($resource);
$contents = stream_get_contents($resource);
$fallbackCall = [$this, $fallback];
return call_user_func($fallbackCall, $path, $contents, $config);
}
示例2: updateStream
/**
* {@inheritdoc}
*/
public function updateStream($path, $resource, array $config = [])
{
if (!is_resource($resource)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
}
$path = Util::normalizePath($path);
$config = $this->prepareConfig($config);
$this->assertPresent($path);
Util::rewindStream($resource);
return (bool) $this->getAdapter()->updateStream($path, $resource, $config);
}
示例3: getStreamAsFile
/**
* Get stream as a file
*
* @param resource $stream
* @return string Filename of resulting stream content
* @throws Exception
*/
protected function getStreamAsFile($stream)
{
// Get temporary file and name
$file = tempnam(sys_get_temp_dir(), 'ssflysystem');
$buffer = fopen($file, 'w');
if (!$buffer) {
throw new Exception("Could not create temporary file");
}
// Transfer from given stream
Util::rewindStream($stream);
stream_copy_to_stream($stream, $buffer);
if (!fclose($buffer)) {
throw new Exception("Could not write stream to temporary file");
}
return $file;
}
示例4: updateStream
/**
* Update a file with the contents of a stream.
*
* @param string $path
* @param resource $resource
* @param mixed $config Config object or visibility setting
*
* @throws InvalidArgumentException
*
* @return bool success boolean
*/
public function updateStream($path, $resource, array $config = [])
{
if (!is_resource($resource)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
}
$path = Util::normalizePath($path);
$config = $this->prepareConfig($config);
$this->assertPresent($path);
Util::rewindStream($resource);
if (!($object = $this->adapter->updateStream($path, $resource, $config))) {
return false;
}
$this->cache->updateObject($path, $object + ['contents' => false], true);
return true;
}
示例5: updateStream
/**
* Update an existing file using a stream.
*
* @param string $path The path of the existing file.
* @param resource $resource The file handle.
* @param array $config An optional configuration array.
*
* @throws InvalidArgumentException If $resource is not a file handle.
* @throws FileNotFoundException
*
* @return bool True on success, false on failure.
*/
public function updateStream($path, $resource, array $config = [])
{
$media = $this->find($path, true);
$realPath = $media->realPath;
if (!($destination = fopen($realPath . '.new', 'w+'))) {
return false;
}
stream_copy_to_stream($resource, $destination);
if (!fclose($destination)) {
return false;
}
$oldPath = $realPath . 'old' . time();
if (!rename($realPath, $oldPath) || !rename($realPath . '.new', $realPath)) {
return false;
}
unlink($oldPath);
Util::rewindStream($resource);
return $media !== null;
}
示例6: updateStream
/**
* Update a file with the contents of a stream
*
* @param string $path
* @param resource $resource
* @param mixed $config Config object or visibility setting
* @return bool success boolean
* @throws InvalidArgumentException
*/
public function updateStream($path, $resource, $config = null)
{
if (!is_resource($resource)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
}
$path = Util::normalizePath($path);
$config = Util::ensureConfig($config);
$config->setFallback($this->getConfig());
$this->assertPresent($path);
Util::rewindStream($resource);
if (!($object = $this->adapter->updateStream($path, $resource, $config))) {
return false;
}
$this->cache->updateObject($path, $object, true);
return true;
}
示例7: putStream
/**
* {@inheritdoc}
*/
public function putStream($path, $resource, $config = [])
{
$resource = $this->normalizeResource($resource, __METHOD__);
$path = $this->normalizePath($path);
$config = $this->prepareConfig($config);
Flysystem\Util::rewindStream($resource);
$this->doPutStream($path, $resource, $config);
}