Skip to content

Commit

Permalink
Drop support Guzzle\Psr7 <1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Jan 3, 2022
1 parent bfbca49 commit 0bd495e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ class AppServiceProvider extends ServiceProvider { // can be a custom ServicePro
$client->refreshToken($config['refreshToken']);
$service = new \Google\Service\Drive($client);
$adapter = new \Masbug\Flysystem\GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
$driver = new \League\Flysystem\Filesystem($adapter);

return new \League\Flysystem\Filesystem($adapter);
return new \Illuminate\Filesystem\FilesystemAdapter($driver);
});
} catch(\Exception $e) {
// ...
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.3 | ^7.0",
"league/flysystem": "^1.0",
"google/apiclient": "^2.2"
"google/apiclient": "^2.2",
"guzzlehttp/psr7": "^1.7|^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0 | ^9.3"
Expand Down
11 changes: 4 additions & 7 deletions src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Google\Service\Drive\DriveFile;
use Google\Service\Drive\FileList;
use Google\Service\Drive\Permission;
use GuzzleHttp\Psr7\Utils;
use League\Flysystem\Adapter\AbstractAdapter;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
Expand Down Expand Up @@ -54,7 +55,7 @@ class GoogleDriveAdapter extends AbstractAdapter
const DIRMIME = 'application/vnd.google-apps.folder';

/**
* Google\Service\Drive instance
* \Google\Service\Drive instance
*
* @var Drive
*/
Expand Down Expand Up @@ -261,7 +262,7 @@ public function __construct($service, $root = null, $options = [])
/**
* Gets the service
*
* @return Google\Service\Drive
* @return \Google\Service\Drive
*/
public function getService()
{
Expand Down Expand Up @@ -1361,11 +1362,7 @@ protected function upload($path, $contents, Config $config, $updating = null)
$file->setMimeType($mime);

/** @var StreamInterface $stream */
if (function_exists('\GuzzleHttp\Psr7\stream_for')) {
$stream = \GuzzleHttp\Psr7\stream_for($contents);
} else {
$stream = \GuzzleHttp\Psr7\Utils::streamFor($contents);
}
$stream = Utils::streamFor($contents);
$size = $stream->getSize();

if ($size <= self::MAX_CHUNK_SIZE) {
Expand Down
24 changes: 4 additions & 20 deletions src/StreamableUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use GuzzleHttp\Psr7\LimitStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Psr7\Utils;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -98,15 +99,7 @@ public function __construct(
$this->client = $client;
$this->request = $request;
$this->mimeType = $mimeType;
if ($data !== null) {
if (function_exists('\GuzzleHttp\Psr7\stream_for')) {
$this->data = \GuzzleHttp\Psr7\stream_for($data);
} else {
$this->data = \GuzzleHttp\Psr7\Utils::streamFor($data);
}
} else {
$this->data = null;
}
$this->data = $data !== null ? Utils::streamFor($data) : null;
$this->resumable = $resumable;
$this->chunkSize = is_bool($chunkSize) ? 0 : $chunkSize;
$this->progress = 0;
Expand Down Expand Up @@ -165,11 +158,7 @@ public function nextChunk($chunk = false)
}
$chunk = new LimitStream($this->data, $this->chunkSize, $this->data->tell());
} else {
if (function_exists('\GuzzleHttp\Psr7\stream_for')) {
$chunk = \GuzzleHttp\Psr7\stream_for($chunk);
} else {
$chunk = \GuzzleHttp\Psr7\Utils::streamFor($chunk);
}
$chunk = Utils::streamFor($chunk);
}
$size = $chunk->getSize();

Expand Down Expand Up @@ -311,13 +300,8 @@ private function process()
}
}
}
if (function_exists('\GuzzleHttp\Psr7\stream_for')) {
$stream = \GuzzleHttp\Psr7\stream_for($postBody);
} else {
$stream = \GuzzleHttp\Psr7\Utils::streamFor($postBody);
}

$request = $request->withBody($stream);
$request = $request->withBody(Utils::streamFor($postBody));

if (isset($contentType) && $contentType) {
$request = $request->withHeader('content-type', $contentType);
Expand Down

0 comments on commit 0bd495e

Please sign in to comment.