My first commit of codes
This commit is contained in:
45
vendor/league/flysystem/src/Adapter/Polyfill/StreamedCopyTrait.php
vendored
Normal file
45
vendor/league/flysystem/src/Adapter/Polyfill/StreamedCopyTrait.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter\Polyfill;
|
||||
|
||||
use League\Flysystem\Config;
|
||||
|
||||
trait StreamedCopyTrait
|
||||
{
|
||||
/**
|
||||
* Copy a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $newpath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function copy($path, $newpath)
|
||||
{
|
||||
$response = $this->readStream($path);
|
||||
|
||||
if ($response === false || ! is_resource($response['stream'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->writeStream($newpath, $response['stream'], new Config());
|
||||
|
||||
if ($result !== false && is_resource($response['stream'])) {
|
||||
fclose($response['stream']);
|
||||
}
|
||||
|
||||
return $result !== false;
|
||||
}
|
||||
|
||||
// Required abstract method
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
abstract public function readStream($path);
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
abstract public function writeStream($path, $resource, Config $config);
|
||||
}
|
||||
Reference in New Issue
Block a user