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

Support FlySystem ^3.0 #52

Merged
merged 1 commit into from
Jan 14, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For example: virtual path `/Xa3X9GlR6EmbnY1RLVTk5VUtOVkk/0B3X9GlR6EmbnY1RLVTk5VU

## Installation

- For **Flysystem V2** or **Laravel >= 9.x.x**
- For **Flysystem V2/V3** or **Laravel >= 9.x.x**

```bash
composer require masbug/flysystem-google-drive-ext
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"php": "^7.2 | ^8.0",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.3 | ^7.0",
"league/flysystem": "^2.1.1",
"league/flysystem": "^2.1.1|^3.0",
"google/apiclient": "^2.2",
"guzzlehttp/psr7": "^1.7|^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0 | ^9.3",
"league/flysystem-adapter-test-utilities": "^2.0"
"league/flysystem-adapter-test-utilities": "^2.0|^3.0"
},
"autoload": {
"psr-4": {
Expand Down
25 changes: 25 additions & 0 deletions src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,20 @@ public function fileExists(string $path): bool
}
}

/**
* @throws FilesystemException
*/
public function directoryExists(string $path): bool
{
try {
$location = $this->prefixer->prefixPath($path);
$this->toVirtualPath($location, true, true);
return true;
} catch (UnableToReadFile $e) {
return false;
}
}

private function writeData(string $location, $contents, Config $config)
{
$updating = null;
Expand Down Expand Up @@ -636,6 +650,17 @@ public function createDirectory(string $dirname, Config $config): void
throw UnableToCreateDirectory::atLocation($dirname, 'Failed to create dir');
}

/**
* {@inheritdoc}
*/
public function has($path): bool
{
if ($this->useDisplayPaths) {
$this->toVirtualPath($path, false);
}
return ($this->getFileObject($path, true) instanceof DriveFile);
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/GoogleDriveAdapterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class GoogleDriveAdapterTests extends FilesystemAdapterTestCase
{
protected $exceptionTypeToRetryOn = null;

/**
* @var string
*/
Expand All @@ -20,6 +22,12 @@ public static function setUpBeforeClass(): void
static::$adapterPrefix = 'ci/'.bin2hex(random_bytes(10));
}

protected function retryOnException(string $className, int $timout = 2): void
{
$this->exceptionTypeToRetryOn = null;
$this->timeoutForExceptionRetry = $timout;
}

protected static function createFilesystemAdapter(): FilesystemAdapter
{
$file = __DIR__.'/../google-drive-service-account.json';
Expand Down