Skip to content

Commit

Permalink
Support FlySystem ^3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Jan 14, 2022
1 parent a402b26 commit a101789
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
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

0 comments on commit a101789

Please sign in to comment.