Skip to content

Commit d65bb0d

Browse files
committed
Update Flysystem usage
1 parent 1e84624 commit d65bb0d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

camel/Camel.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ public static function loadEndpointsFromCamelFiles(string $folder, callable $cal
6464
$contents = Utils::listDirectoryContents($folder);
6565

6666
foreach ($contents as $object) {
67-
// todo Flysystem v1 had items as arrays; v2 has objects.
68-
// v2 allows ArrayAccess, but when we drop v1 support (Laravel <9), we should switch to methods
6967
if (
70-
$object['type'] == 'file'
71-
&& Str::endsWith(basename($object['path']), '.yaml')
72-
&& !Str::startsWith(basename($object['path']), 'custom.')
68+
$object->isFile()
69+
&& Str::endsWith(basename($object->path()), '.yaml')
70+
&& !Str::startsWith(basename($object->path()), 'custom.')
7371
) {
7472
$group = Yaml::parseFile($object['path']);
7573
$callback($group);
@@ -83,14 +81,12 @@ public static function loadUserDefinedEndpoints(string $folder): array
8381

8482
$userDefinedEndpoints = [];
8583
foreach ($contents as $object) {
86-
// todo Flysystem v1 had items as arrays; v2 has objects.
87-
// v2 allows ArrayAccess, but when we drop v1 support (Laravel <9), we should switch to methods
8884
if (
89-
$object['type'] == 'file'
90-
&& Str::endsWith(basename($object['path']), '.yaml')
91-
&& Str::startsWith(basename($object['path']), 'custom.')
85+
$object->isFile()
86+
&& Str::endsWith(basename($object->path()), '.yaml')
87+
&& Str::startsWith(basename($object->path()), 'custom.')
9288
) {
93-
$endpoints = Yaml::parseFile($object['path']);
89+
$endpoints = Yaml::parseFile($object->path());
9490
foreach (($endpoints ?: []) as $endpoint) {
9591
$userDefinedEndpoints[] = $endpoint;
9692
}

src/Tools/Utils.php

+7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Knuckles\Scribe\Exceptions\CouldntGetRouteDetails;
1616
use Knuckles\Scribe\ScribeServiceProvider;
1717
use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
18+
use League\Flysystem\DirectoryListing;
1819
use League\Flysystem\Filesystem;
20+
use League\Flysystem\FilesystemException;
1921
use League\Flysystem\Local\LocalFilesystemAdapter;
2022
use Mpociot\Reflection\DocBlock\Tag;
2123
use ReflectionClass;
@@ -125,6 +127,11 @@ public static function deleteDirectoryAndContents(string $dir, ?string $workingD
125127
$fs->deleteDirectory($dir);
126128
}
127129

130+
/**
131+
* @param string $dir
132+
* @return DirectoryListing<\League\Flysystem\StorageAttributes>
133+
* @throws FilesystemException
134+
*/
128135
public static function listDirectoryContents(string $dir)
129136
{
130137
$adapter = new LocalFilesystemAdapter(getcwd());

0 commit comments

Comments
 (0)