v2: Updates

* Simplifies & beautifies everything
* Introduces a new Class system.
* Errors are defaulted to AWS's handler.
* New function names & more efficient handling.
* Should fix a majority of the errors.

Please read the README for more!
This commit is contained in:
Devang Srivastava 2020-09-28 15:32:51 +05:30
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -94,6 +94,9 @@ class StreamWrapper
/** @var string The opened protocol (e.g., "s3") */
private $protocol = 's3';
/** @var bool Keeps track of whether stream has been flushed since opening */
private $isFlushed = false;
/**
* Register the 's3://' stream wrapper
*
@ -127,12 +130,16 @@ class StreamWrapper
public function stream_close()
{
if ($this->body->getSize() === 0 && !($this->isFlushed)) {
$this->stream_flush();
}
$this->body = $this->cache = null;
}
public function stream_open($path, $mode, $options, &$opened_path)
{
$this->initProtocol($path);
$this->isFlushed = false;
$this->params = $this->getBucketKey($path);
$this->mode = rtrim($mode, 'bt');
@ -140,11 +147,11 @@ class StreamWrapper
return $this->triggerError($errors);
}
return $this->boolCall(function() use ($path) {
return $this->boolCall(function() {
switch ($this->mode) {
case 'r': return $this->openReadStream($path);
case 'a': return $this->openAppendStream($path);
default: return $this->openWriteStream($path);
case 'r': return $this->openReadStream();
case 'a': return $this->openAppendStream();
default: return $this->openWriteStream();
}
});
}
@ -156,6 +163,7 @@ class StreamWrapper
public function stream_flush()
{
$this->isFlushed = true;
if ($this->mode == 'r') {
return false;
}
@ -174,7 +182,7 @@ class StreamWrapper
$params['ContentType'] = $type;
}
$this->clearCacheKey("s3://{$params['Bucket']}/{$params['Key']}");
$this->clearCacheKey("{$this->protocol}://{$params['Bucket']}/{$params['Key']}");
return $this->boolCall(function () use ($params) {
return (bool) $this->getClient()->putObject($params);
});
@ -281,10 +289,10 @@ class StreamWrapper
// Return as if it is a bucket to account for console
// bucket objects (e.g., zero-byte object "foo/")
return $this->formatUrlStat($path);
} else {
// Attempt to stat and cache regular object
return $this->formatUrlStat($result->toArray());
}
// Attempt to stat and cache regular object
return $this->formatUrlStat($result->toArray());
} catch (S3Exception $e) {
// Maybe this isn't an actual key, but a prefix. Do a prefix
// listing of objects to determine.
@ -446,7 +454,7 @@ class StreamWrapper
*/
public function dir_rewinddir()
{
$this->boolCall(function() {
return $this->boolCall(function() {
$this->objectIterator = null;
$this->dir_opendir($this->openedPath, null);
return true;
@ -945,6 +953,6 @@ class StreamWrapper
{
$size = $this->body->getSize();
return $size !== null ? $size : $this->size;
return !empty($size) ? $size : $this->size;
}
}