diff --git a/README.md b/README.md index 59af819..0abdd97 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/DefaultEnvironment.php b/src/DefaultEnvironment.php index c75824b..ca7d8fd 100644 --- a/src/DefaultEnvironment.php +++ b/src/DefaultEnvironment.php @@ -68,17 +68,28 @@ public static function get(string $name) } /** - * Return the environment name. + * Return the environment type. * * For example: "local" or "ci" or "dev" or "prod". * * @return string|bool - * The name of the environment. + * The type of the environment. */ public static function getEnvironment(): string|bool { return static::get(static::ENVIRONMENT_NAME); } + + /** + * Return the user-defined environment name. + * + * @return string|bool + * The name of the environment. + */ + public static function getEnvironmentName(): string|bool + { + return static::getEnvironment(); + } /** * Determine if this is a production environment. diff --git a/src/Environment.php b/src/Environment.php index eaf291a..6f487d9 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -7,8 +7,10 @@ * Helpers for working with the Drupal environment. * * @method static string getEnvironment() + * @method static string|bool getEnvironmentName() * @method static bool isAcquia() * @method static bool isPantheon() + * @method static bool isPlatformSh() * @method static bool isProduction() * @method static bool isStaging() * @method static bool isDevelopment() @@ -29,6 +31,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..923bd1a --- /dev/null +++ b/src/PlatformSh.php @@ -0,0 +1,93 @@ + false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -131,6 +132,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => true, 'isStaging' => false, 'isDevelopment' => false, @@ -158,6 +160,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -184,6 +187,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => true, 'isStaging' => false, 'isDevelopment' => false, @@ -216,6 +220,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => true, 'isDevelopment' => false, @@ -248,6 +253,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => true, @@ -280,6 +286,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -309,6 +316,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -334,6 +342,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => true, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -348,6 +357,127 @@ public static function providerEnvironment(): array ], ], ], + 'platformsh-prod' => [ + [ + 'ENV' => [ + 'PLATFORM_ENVIRONMENT' => 'main-asdf123', + 'PLATFORM_ENVIRONMENT_TYPE' => 'production', + ], + ], + [ + 'getEnvironment' => 'production', + 'getEnvironmentName' => 'main-asdf123', + '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' => '#e7131a', + 'fg_color' => '#ffffff', + ], + ], + ], + 'platformsh-stage' => [ + [ + 'ENV' => [ + 'PLATFORM_ENVIRONMENT' => 'stage-asdf123', + 'PLATFORM_ENVIRONMENT_TYPE' => 'staging', + ], + ], + [ + 'getEnvironment' => 'staging', + 'getEnvironmentName' => 'stage-asdf123', + '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' => '#b85c00', + 'fg_color' => '#ffffff', + ], + ], + ], + 'platformsh-dev' => [ + [ + 'ENV' => [ + 'PLATFORM_ENVIRONMENT' => 'develop-asdf123', + 'PLATFORM_ENVIRONMENT_TYPE' => 'development', + ], + ], + [ + 'getEnvironment' => 'development', + 'getEnvironmentName' => 'develop-asdf123', + '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' => '#307b24', + 'fg_color' => '#ffffff', + ], + ], + ], + 'platformsh-preview' => [ + [ + 'ENV' => [ + 'PLATFORM_ENVIRONMENT' => 'pr-225-asdf123', + 'PLATFORM_BRANCH' => 'pr-225', + 'PLATFORM_ENVIRONMENT_TYPE' => 'development', + ], + ], + [ + 'getEnvironment' => 'development', + 'getEnvironmentName' => 'pr-225-asdf123', + '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' => '#990055', + 'fg_color' => '#ffffff', + ], + ], + ], 'tugboat' => [ [ 'ENV' => [ @@ -362,6 +492,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => true, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -390,6 +521,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -414,6 +546,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -438,6 +571,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => true, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -461,6 +595,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, @@ -488,6 +623,7 @@ public static function providerEnvironment(): array 'isGitLabCi' => false, 'isTugboat' => false, 'isPantheon' => false, + 'isPlatformSh' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false,