Skip to content

Commit

Permalink
Merge pull request #15 from mihaileu/feature/support_flysystem3
Browse files Browse the repository at this point in the history
add compatibility with flysystem 3
  • Loading branch information
RoyVoetman authored Jan 27, 2022
2 parents 2fce767 + 92e058f commit 876ae0d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3",
"league/flysystem": "^2.0.0"
"guzzlehttp/guzzle": "^7.0",
"league/flysystem": "^2.0 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.2"
Expand Down
12 changes: 12 additions & 0 deletions src/GitlabAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use League\Flysystem\FilesystemException;
use League\Flysystem\PathPrefixer;
use League\Flysystem\StorageAttributes;
use League\Flysystem\UnableToCheckExistence;
use League\Flysystem\UnableToCheckFileExistence;
use League\Flysystem\UnableToCopyFile;
use League\Flysystem\UnableToCreateDirectory;
Expand Down Expand Up @@ -378,4 +379,15 @@ public function setClient(Client $client)
{
$this->client = $client;
}

public function directoryExists(string $path): bool
{
try {
$tree = $this->client->tree($this->prefixer->prefixPath($path));

return (bool)count($tree->current());
} catch (Throwable $e) {
throw UnableToCheckExistence::forLocation($path, $e);
}
}
}
19 changes: 19 additions & 0 deletions tests/GitlabAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,25 @@ public function it_throws_when_setting_visibility()

$this->gitlabAdapter->setVisibility('README.md', 0777);
}

/**
* @test
*/
public function it_can_check_directory_if_exists()
{
$dir = 'test-dir/test-dir2/test-dir3';
$this->gitlabAdapter->createDirectory($dir, new Config());
$this->assertTrue($this->gitlabAdapter->directoryExists($dir));
$this->gitlabAdapter->deleteDirectory($dir);
}

/**
* @test
*/
public function it_cannot_check_if_directory_exists()
{
$this->assertFalse($this->gitlabAdapter->directoryExists('test_non_existent_dir'));
}

private function setInvalidToken()
{
Expand Down

0 comments on commit 876ae0d

Please sign in to comment.