Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2] Drop support for Guzzle\Psr7 <1.7 and merge V1 changes #51

Merged
merged 15 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/docs export-ignore
/tests export-ignore
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,16 @@ try {
##### How to get TeamDrive list and IDs

```php
$client = new \Google\Client();
$client->setClientId([client_id]);
$client->setClientSecret([client_secret]);
$client->refreshToken([refresh_token]);
$client->setApplicationName('My Google Drive App');

$service = new \Google\Service\Drive($client);

$drives = $service->teamdrives->listTeamdrives()->getTeamDrives();
$drives = $fs->getAdapter()->getService()->teamdrives->listTeamdrives()->getTeamDrives();
foreach ($drives as $drive) {
echo 'TeamDrive: ' . $drive->name . PHP_EOL;
echo 'ID: ' . $drive->id . PHP_EOL;
echo 'ID: ' . $drive->id . PHP_EOL. PHP_EOL;
}
```

##### How permanently deletes all of the user's trashed files
```php
$fs->getAdapter()->emptyTrash([]);
```

## Using with Laravel Framework
Expand Down Expand Up @@ -205,7 +201,10 @@ Example:
```php
namespace App\Providers;

class AppServiceProvider extends \Illuminate\Support\ServiceProvider{ // can be a custom ServiceProvider
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider { // can be a custom ServiceProvider
// ...
public function boot(){
// ...
Expand All @@ -225,6 +224,7 @@ class AppServiceProvider extends \Illuminate\Support\ServiceProvider{ // can be
$service = new \Google\Service\Drive($client);
$adapter = new \Masbug\Flysystem\GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
$driver = new \League\Flysystem\Filesystem($adapter);

return new \Illuminate\Filesystem\FilesystemAdapter($driver, $adapter);
});
} 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": "^2.1.1",
"google/apiclient": "^2.2"
"google/apiclient": "^2.2",
"guzzlehttp/psr7": "^1.7|^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0 | ^9.3",
Expand Down
19 changes: 8 additions & 11 deletions src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Google\Service\Drive\DriveFile;
use Google\Service\Drive\FileList;
use Google\Service\Drive\Permission;
use GuzzleHttp\Psr7\Utils;
use League\Flysystem\Config;
use League\Flysystem\DirectoryAttributes;
use League\Flysystem\FileAttributes;
Expand Down Expand Up @@ -70,7 +71,7 @@ class GoogleDriveAdapter implements FilesystemAdapter
const DIRMIME = 'application/vnd.google-apps.folder';

/**
* Google\Service\Drive instance
* \Google\Service\Drive instance
*
* @var Drive
*/
Expand Down Expand Up @@ -282,7 +283,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 @@ -1020,7 +1021,7 @@ protected function publish($path)
$file->setPermissions([$permission]);
return true;
}
} catch (Exception $e) {
} catch (\Exception $e) {
return false;
}
}
Expand All @@ -1047,7 +1048,7 @@ protected function unPublish($path)
}
$file->setPermissions([]);
return true;
} catch (Exception $e) {
} catch (\Exception $e) {
return false;
}
}
Expand Down Expand Up @@ -1122,7 +1123,7 @@ protected function normaliseObject(DriveFile $object, $dirname)
break;
}
}
} catch (Exception $e) {
} catch (\Exception $e) {
// Unnecesary
}
if ($this->useDisplayPaths) {
Expand Down Expand Up @@ -1206,7 +1207,7 @@ protected function getItems($dirname, $recursive = false, $maxResults = 0, $quer
} else {
$pageToken = null;
}
} catch (Exception $e) {
} catch (\Exception $e) {
$pageToken = null;
}
} while ($pageToken && $maxResults === 0);
Expand Down Expand Up @@ -1369,11 +1370,7 @@ protected function upload($path, $contents, Config $config, $updating = null)
$file->setMimeType($mime);

/** @var StreamInterface $stream */
if (function_exists('\GuzzleHttp\Psr7\stream_for')) {
$stream = /** @scrutinizer ignore-call */ \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 = /** @scrutinizer ignore-call */ \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 = /** @scrutinizer ignore-call */ \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 = /** @scrutinizer ignore-call */ \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