From 0c889a2848613e8c3d3c7529982d51318245195f Mon Sep 17 00:00:00 2001 From: Aaron Feledy Date: Sat, 1 Jul 2023 17:35:23 -0500 Subject: [PATCH] Add support for Platform.sh --- README.md | 1 + src/Environment.php | 2 + src/PlatformSh.php | 87 +++++++++++++++++++++++ tests/src/EnvironmentTest.php | 128 ++++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 src/PlatformSh.php diff --git a/README.md b/README.md index d3cfc2a..10f92eb 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ use DrupalEnvironment\Environment; // These all return a boolean true/false Environment::isPantheon(); +Environment::isPlatformSh(); Environment::isAcquia(); Environment::isTugboat(); Environment::isGitHubWorkflow(); diff --git a/src/Environment.php b/src/Environment.php index f7feca0..3c8961d 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -8,6 +8,7 @@ * @method static string getEnvironment() * @method static bool isAcquia() * @method static bool isPantheon() + * @method static bool isPlatformSh() * @method static bool isProduction() * @method static bool isStaging() * @method static bool isDevelopment() @@ -28,6 +29,7 @@ class Environment public const CLASSES = [ 'isAcquia' => Acquia::class, 'isPantheon' => Pantheon::class, + 'isPlatformSh' => PlatformSh::class, 'isTugboat' => Tugboat::class, 'isGitHubWorkflow' => GitHubWorkflow::class, 'isGitLabCi' => GitLabCi::class, diff --git a/src/PlatformSh.php b/src/PlatformSh.php new file mode 100644 index 0000000..18847b0 --- /dev/null +++ b/src/PlatformSh.php @@ -0,0 +1,87 @@ + false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -99,6 +100,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => true, 'isStaging' => false, 'isDevelopment' => false, @@ -124,6 +126,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -145,6 +148,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => true, 'isStaging' => false, 'isDevelopment' => false, @@ -171,6 +175,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => true, 'isDevelopment' => false, @@ -197,6 +202,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => true, @@ -223,6 +229,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -249,6 +256,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -271,6 +279,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -285,6 +294,119 @@ public function providerEnvironment(): array ], ], ], + 'platformsh-prod' => [ + [ + 'PLATFORM_ENVIRONMENT' => 'main-asdf123', + 'PLATFORM_ENVIRONMENT_TYPE' => 'production', + ], + [ + 'getEnvironment' => 'main-asdf123', + 'getEnvironmentType' => 'production', + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isTugboat' => false, + 'isPantheon' => false, + 'isPlatformSh' => true, + 'isProduction' => true, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => false, + 'getIndicatorConfig' => [ + 'name' => 'Production', + 'bg_color' => '#ffffff', + 'fg_color' => '#e7131a', + ], + ], + ], + 'platformsh-stage' => [ + [ + 'PLATFORM_ENVIRONMENT' => 'stage-asdf123', + 'PLATFORM_ENVIRONMENT_TYPE' => 'staging', + ], + [ + 'getEnvironment' => 'stage-asdf123', + 'getEnvironmentType' => 'staging', + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isTugboat' => false, + 'isPantheon' => false, + 'isPlatformSh' => true, + 'isProduction' => false, + 'isStaging' => true, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => false, + 'getIndicatorConfig' => [ + 'name' => 'Staging', + 'bg_color' => '#ffffff', + 'fg_color' => '#b85c00', + ], + ], + ], + 'platformsh-dev' => [ + [ + 'PLATFORM_ENVIRONMENT' => 'develop-asdf123', + 'PLATFORM_ENVIRONMENT_TYPE' => 'development', + ], + [ + 'getEnvironment' => 'develop-asdf123', + 'getEnvironmentType' => 'development', + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isTugboat' => false, + 'isPantheon' => false, + 'isPlatformSh' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => true, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => false, + 'getIndicatorConfig' => [ + 'name' => 'Development', + 'bg_color' => '#ffffff', + 'fg_color' => '#307b24', + ], + ], + ], + 'platformsh-preview' => [ + [ + 'PLATFORM_ENVIRONMENT' => 'pr-225-asdf123', + 'PLATFORM_BRANCH' => 'pr-225', + 'PLATFORM_ENVIRONMENT_TYPE' => 'development', + ], + [ + 'getEnvironment' => 'pr-225-asdf123', + 'getEnvironmentType' => 'development', + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isTugboat' => false, + 'isPantheon' => false, + 'isPlatformSh' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => true, + 'isCi' => false, + 'isLocal' => false, + 'getIndicatorConfig' => [ + 'name' => 'Preview', + 'bg_color' => '#ffffff', + 'fg_color' => '#990055', + ], + ], + ], 'tugboat' => [ [ 'TUGBOAT_PREVIEW_NAME' => 'phpunit', @@ -297,6 +419,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => true, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -323,6 +446,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -345,6 +469,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -367,6 +492,7 @@ public function providerEnvironment(): array 'isGitLabCi' => true, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -388,6 +514,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -413,6 +540,7 @@ public function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false,