From 4f539f1ed48a99fdec0f27be759d38d6192a1585 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 30 Nov 2023 16:04:15 +1300 Subject: [PATCH] Update switch to match --- app/init.php | 85 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/app/init.php b/app/init.php index f2063870ac..82e2baf804 100644 --- a/app/init.php +++ b/app/init.php @@ -1290,46 +1290,51 @@ function getDevice($root): Device default => new Local($root), }; } else { - switch (strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) ?? '')) { - case Storage::DEVICE_LOCAL: - default: - return new Local($root); - case Storage::DEVICE_S3: - $s3AccessKey = App::getEnv('_APP_STORAGE_S3_ACCESS_KEY', ''); - $s3SecretKey = App::getEnv('_APP_STORAGE_S3_SECRET', ''); - $s3Region = App::getEnv('_APP_STORAGE_S3_REGION', ''); - $s3Bucket = App::getEnv('_APP_STORAGE_S3_BUCKET', ''); - $s3Acl = 'private'; - return new S3($root, $s3AccessKey, $s3SecretKey, $s3Bucket, $s3Region, $s3Acl); - case Storage::DEVICE_DO_SPACES: - $doSpacesAccessKey = App::getEnv('_APP_STORAGE_DO_SPACES_ACCESS_KEY', ''); - $doSpacesSecretKey = App::getEnv('_APP_STORAGE_DO_SPACES_SECRET', ''); - $doSpacesRegion = App::getEnv('_APP_STORAGE_DO_SPACES_REGION', ''); - $doSpacesBucket = App::getEnv('_APP_STORAGE_DO_SPACES_BUCKET', ''); - $doSpacesAcl = 'private'; - return new DOSpaces($root, $doSpacesAccessKey, $doSpacesSecretKey, $doSpacesBucket, $doSpacesRegion, $doSpacesAcl); - case Storage::DEVICE_BACKBLAZE: - $backblazeAccessKey = App::getEnv('_APP_STORAGE_BACKBLAZE_ACCESS_KEY', ''); - $backblazeSecretKey = App::getEnv('_APP_STORAGE_BACKBLAZE_SECRET', ''); - $backblazeRegion = App::getEnv('_APP_STORAGE_BACKBLAZE_REGION', ''); - $backblazeBucket = App::getEnv('_APP_STORAGE_BACKBLAZE_BUCKET', ''); - $backblazeAcl = 'private'; - return new Backblaze($root, $backblazeAccessKey, $backblazeSecretKey, $backblazeBucket, $backblazeRegion, $backblazeAcl); - case Storage::DEVICE_LINODE: - $linodeAccessKey = App::getEnv('_APP_STORAGE_LINODE_ACCESS_KEY', ''); - $linodeSecretKey = App::getEnv('_APP_STORAGE_LINODE_SECRET', ''); - $linodeRegion = App::getEnv('_APP_STORAGE_LINODE_REGION', ''); - $linodeBucket = App::getEnv('_APP_STORAGE_LINODE_BUCKET', ''); - $linodeAcl = 'private'; - return new Linode($root, $linodeAccessKey, $linodeSecretKey, $linodeBucket, $linodeRegion, $linodeAcl); - case Storage::DEVICE_WASABI: - $wasabiAccessKey = App::getEnv('_APP_STORAGE_WASABI_ACCESS_KEY', ''); - $wasabiSecretKey = App::getEnv('_APP_STORAGE_WASABI_SECRET', ''); - $wasabiRegion = App::getEnv('_APP_STORAGE_WASABI_REGION', ''); - $wasabiBucket = App::getEnv('_APP_STORAGE_WASABI_BUCKET', ''); - $wasabiAcl = 'private'; - return new Wasabi($root, $wasabiAccessKey, $wasabiSecretKey, $wasabiBucket, $wasabiRegion, $wasabiAcl); - } + $device = strtolower(App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) ?? ''); + + return match ($device) { + Storage::DEVICE_S3 => new S3( + $root, + App::getEnv('_APP_STORAGE_S3_ACCESS_KEY', ''), + App::getEnv('_APP_STORAGE_S3_SECRET', ''), + App::getEnv('_APP_STORAGE_S3_BUCKET', ''), + App::getEnv('_APP_STORAGE_S3_REGION', ''), + 'private' + ), + Storage::DEVICE_DO_SPACES => new DOSpaces( + $root, + App::getEnv('_APP_STORAGE_DO_SPACES_ACCESS_KEY', ''), + App::getEnv('_APP_STORAGE_DO_SPACES_SECRET', ''), + App::getEnv('_APP_STORAGE_DO_SPACES_BUCKET', ''), + App::getEnv('_APP_STORAGE_DO_SPACES_REGION', ''), + 'private' + ), + Storage::DEVICE_BACKBLAZE => new Backblaze( + $root, + App::getEnv('_APP_STORAGE_BACKBLAZE_ACCESS_KEY', ''), + App::getEnv('_APP_STORAGE_BACKBLAZE_SECRET', ''), + App::getEnv('_APP_STORAGE_BACKBLAZE_BUCKET', ''), + App::getEnv('_APP_STORAGE_BACKBLAZE_REGION', ''), + 'private' + ), + Storage::DEVICE_LINODE => new Linode( + $root, + App::getEnv('_APP_STORAGE_LINODE_ACCESS_KEY', ''), + App::getEnv('_APP_STORAGE_LINODE_SECRET', ''), + App::getEnv('_APP_STORAGE_LINODE_BUCKET', ''), + App::getEnv('_APP_STORAGE_LINODE_REGION', ''), + 'private' + ), + Storage::DEVICE_WASABI => new Wasabi( + $root, + App::getEnv('_APP_STORAGE_WASABI_ACCESS_KEY', ''), + App::getEnv('_APP_STORAGE_WASABI_SECRET', ''), + App::getEnv('_APP_STORAGE_WASABI_BUCKET', ''), + App::getEnv('_APP_STORAGE_WASABI_REGION', ''), + 'private' + ), + default => new Local($root), + }; } }