-
Notifications
You must be signed in to change notification settings - Fork 7
Feature laravel13 #90
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
Changes from all commits
3e8abce
1243dc7
1639a56
5797303
25ee9d5
36dd5b3
501076c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace CodebarAg\FlysystemCloudinary; | ||
|
|
||
| use Cloudinary\Cloudinary; | ||
| use Throwable; | ||
|
|
||
| final class CloudinaryAdminFolderLocator | ||
| { | ||
| public function folderExists(Cloudinary $cloudinary, string $prefixedPath): bool | ||
| { | ||
| $pos = strrpos($prefixedPath, '/'); | ||
| $needle = $pos === false ? '' : substr($prefixedPath, 0, $pos); | ||
|
|
||
| try { | ||
| $folders = []; | ||
| $response = null; | ||
| do { | ||
| $response = (array) $cloudinary->adminApi()->subFolders($needle, [ | ||
| 'max_results' => 500, | ||
| 'next_cursor' => $response['next_cursor'] ?? null, | ||
| ]); | ||
|
Comment on lines
+16
to
+22
|
||
|
|
||
| $folders = array_merge($folders, $response['folders'] ?? []); | ||
| } while (! empty($response['next_cursor'])); | ||
|
|
||
| foreach ($folders as $folder) { | ||
| if (($folder['path'] ?? '') === $prefixedPath) { | ||
| return true; | ||
| } | ||
| } | ||
| } catch (Throwable) { | ||
| return false; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| namespace CodebarAg\FlysystemCloudinary; | ||
|
|
||
| use League\Flysystem\Config; | ||
|
|
||
| final readonly class CloudinaryDiskOptions | ||
| { | ||
| /** | ||
| * @param array<string, mixed> $globalUploadOptions | ||
| */ | ||
| public function __construct( | ||
| public ?string $folder, | ||
| public ?string $uploadPreset, | ||
| public array $globalUploadOptions, | ||
| public bool $preferSecureUrl, | ||
| ) {} | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $diskConfig | ||
| */ | ||
| public static function fromDiskAndConfig(array $diskConfig): self | ||
| { | ||
| $publishedOptions = config('flysystem-cloudinary.options', []); | ||
|
|
||
| $options = $diskConfig['options'] ?? null; | ||
| if (! is_array($options)) { | ||
| $options = is_array($publishedOptions) ? $publishedOptions : []; | ||
| } | ||
|
|
||
| return new self( | ||
| folder: self::nullableString($diskConfig['folder'] ?? config('flysystem-cloudinary.folder')), | ||
| uploadPreset: self::nullableString($diskConfig['upload_preset'] ?? config('flysystem-cloudinary.upload_preset')), | ||
| globalUploadOptions: $options, | ||
| preferSecureUrl: (bool) ($diskConfig['secure_url'] ?? config('flysystem-cloudinary.secure_url', true)), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Merge base upload API options with disk + Flysystem {@see Config} overrides. | ||
| * | ||
| * @return array<string, mixed> | ||
| */ | ||
| public function uploadOptionsFor(string $logicalPublicId, Config $config): array | ||
| { | ||
| $base = [ | ||
| 'type' => 'upload', | ||
| 'public_id' => $logicalPublicId, | ||
| 'invalidate' => true, | ||
| 'use_filename' => true, | ||
| 'resource_type' => 'auto', | ||
| 'unique_filename' => false, | ||
| ]; | ||
|
|
||
| $fromDisk = array_filter([ | ||
| 'folder' => $this->folder, | ||
| 'upload_preset' => $this->uploadPreset, | ||
| ], static fn ($v) => $v !== null && $v !== ''); | ||
|
|
||
| $merged = array_merge($base, $fromDisk, $this->globalUploadOptions); | ||
|
|
||
| $flyOptions = $config->get('options'); | ||
| if (is_array($flyOptions) && $flyOptions !== []) { | ||
| $merged = array_merge($merged, $flyOptions); | ||
| } | ||
|
|
||
| return $merged; | ||
| } | ||
|
|
||
| private static function nullableString(mixed $value): ?string | ||
| { | ||
| if ($value === null || $value === '') { | ||
| return null; | ||
| } | ||
|
|
||
| return (string) $value; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
"minimum-stability": "dev"for the package increases the chance that CI/dev installs resolve to dev releases of dependencies (especially underprefer-lowest), which can make the test matrix flaky and harder to reproduce. Unless this is required for a specific dependency, consider keepingminimum-stabilityatstableand relying on explicit version constraints /@devflags only where needed.