-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3421f58
commit 0c889a2
Showing
4 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace DrupalEnvironment; | ||
|
||
/** | ||
* The Platform.sh environment specifics. | ||
* | ||
* @see https://docs.platform.sh/environments.html | ||
* | ||
* @internal | ||
*/ | ||
class PlatformSh extends DefaultEnvironment | ||
{ | ||
|
||
/** | ||
* The default environment variable name. | ||
* | ||
* @var string | ||
*/ | ||
public const ENVIRONMENT_TYPE = 'PLATFORM_ENVIRONMENT_TYPE'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public const ENVIRONMENT_NAME = 'PLATFORM_ENVIRONMENT'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public const PRODUCTION = 'production'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public const STAGING = 'staging'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public const DEVELOPMENT = 'development'; | ||
|
||
/** | ||
* Return the environment type. | ||
* | ||
* For example: "local" or "development" or "production". | ||
* | ||
* @return string | ||
* The type of the environment. | ||
*/ | ||
public static function getEnvironmentType(): string | ||
{ | ||
return static::get(static::ENVIRONMENT_TYPE) ?: 'local'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function isProduction(): bool | ||
{ | ||
return static::getEnvironmentType() === static::PRODUCTION; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function isStaging(): bool | ||
{ | ||
return static::getEnvironmentType() === static::STAGING; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function isDevelopment(): bool | ||
{ | ||
return static::getEnvironmentType() === static::DEVELOPMENT && !static::isPreview(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function isPreview(): bool | ||
{ | ||
// If the branch looks like "pr-123" then it's a pull request environment. | ||
return preg_match('/^pr-\d+$/', static::get("PLATFORM_BRANCH")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters