diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f6db49..bda5017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,5 +50,8 @@ All notable changes to `flysystem-gitlab-storage` will be documented in this fil ### 2.0.4 - 2020-12-16 - Savings HTTP exchanges with HEAD request -### 2.xx - 2024-xx-xx +### 3.0.0 - 2022-01-27 +- Added flysystem v3 support. + +### 3.1.0 - 2024-04-26 - Moved minimum PHP version to 8.1 \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index e9edd6a..27c9153 100644 --- a/src/Client.php +++ b/src/Client.php @@ -82,7 +82,7 @@ public function read($path) $headers = $response->getHeaders(); $headers = array_filter( $headers, - fn($key) => substr($key, 0, 9) == 'X-Gitlab-', + fn($key) => substr($key, 0, 9) == 'x-gitlab-', ARRAY_FILTER_USE_KEY ); @@ -294,9 +294,11 @@ private function request(string $method, string $uri, array $params = []): Respo private function buildUri(string $uri, array $params = []): string { $params = array_merge(['ref' => $this->branch], $params); - - $params = array_map('urlencode', $params); - + + $params = array_map(function($value) { + return $value !== null ? urlencode($value) : null; + }, $params); + if(isset($params['path'])) { $params['path'] = urldecode($params['path']); } diff --git a/src/GitlabAdapter.php b/src/GitlabAdapter.php index b519f8b..48ee1b7 100644 --- a/src/GitlabAdapter.php +++ b/src/GitlabAdapter.php @@ -325,6 +325,10 @@ public function directoryExists(string $path): bool return (bool)count($tree->current()); } catch (Throwable $e) { + if ($e instanceof ClientException && $e->getCode() == 404) { + return false; + } + throw UnableToCheckExistence::forLocation($path, $e); } } diff --git a/tests/GitlabAdapterTest.php b/tests/GitlabAdapterTest.php index cfbeaaa..f474df3 100644 --- a/tests/GitlabAdapterTest.php +++ b/tests/GitlabAdapterTest.php @@ -289,9 +289,12 @@ public function it_can_retrieve_a_list_of_contents_of_root_recursive() $list = $this->gitlabAdapter->listContents('/', true); $expectedPaths = [ ['type' => 'dir', 'path' => 'recursive'], + ['type' => 'dir', 'path' => 'recursive/level-1'], + ['type' => 'dir', 'path' => 'recursive/level-1/level-2'], ['type' => 'file', 'path' => 'LICENSE'], ['type' => 'file', 'path' => 'README.md'], ['type' => 'file', 'path' => 'recursive/recursive.testing.md'], + ['type' => 'file', 'path' => 'recursive/level-1/level-2/.gitkeep'], ['type' => 'file', 'path' => 'test'], ['type' => 'file', 'path' => 'test2'], ]; @@ -309,7 +312,26 @@ public function it_can_retrieve_a_list_of_contents_of_sub_folder() { $list = $this->gitlabAdapter->listContents('/recursive', false); $expectedPaths = [ - ['type' => 'file', 'path' => 'recursive/recursive.testing.md'] + ['type' => 'dir', 'path' => 'recursive/level-1'], + ['type' => 'dir', 'path' => 'recursive/level-1/level-2'], + ['type' => 'file', 'path' => 'recursive/recursive.testing.md'], + ['type' => 'file', 'path' => 'recursive/level-1/level-2/.gitkeep'], + ]; + + foreach ($list as $item) { + $this->assertInstanceOf(StorageAttributes::class, $item); + $this->assertContains( + ['type' => $item['type'], 'path' => $item['path']], $expectedPaths + ); + } + } + + #[Test] + public function it_can_retrieve_a_list_of_contents_of_deep_sub_folder() + { + $list = $this->gitlabAdapter->listContents('/recursive/level-1/level-2', false); + $expectedPaths = [ + ['type' => 'file', 'path' => 'recursive/level-1/level-2/.gitkeep'], ]; foreach ($list as $item) {