davereid/drupal-environment
最新稳定版本:1.1.0
Composer 安装命令:
composer require davereid/drupal-environment
包简介
Provides a helper for working with environment variables and Drupal hosting providers.
README 文档
README
Provides a class for working with Drupal environments and environment variables.
This also standardizes some environment terminology between hosting providers so that you can use the same code across different hosts:
| Environment | Acquia | Pantheon |
|---|---|---|
| Production | prod |
live |
| Staging | test |
test |
| Development | dev |
dev |
Basic Usage
Getting an environment variable
use DrupalEnvironment\Environment; $value = Environment::get('VARIABLE_NAME');
The advantages of using this is the results are statically cached.
Testing for Drupal hosting or CI environments
use DrupalEnvironment\Environment; // These all return a boolean true/false Environment::isPantheon(); Environment::isAcquia(); Environment::isTugboat(); Environment::isGitHubWorkflow(); Environment::isGitLabCi(); Environment::isCircleCi();
Testing for specific environments
use DrupalEnvironment\Environment; // This gets the specific environment string. $environment = Environment::getEnvironment(); // These all return a boolean true/false Environment::isProduction(); Environment::isStaging(); Environment::isDevelopment(); Environment::isCi(); Environment::isLocal(); // Covers both DDEV and Lando Environment::isDdev(); Environment::isLando();
Testing for executable commands
use DrupalEnvironment\Environment; // This returns a boolean true/false: Environment::commandExists('composer');
Example usage
settings.php
use DrupalEnvironment\Environment; // Add configuration for the Environment Indicator module. $config['environment_indicator.indicator'] = Environment::getIndicatorConfig(); if (Environment::isProduction()) { // Set some production environment settings overrides. } elseif (Environment::isStaging()) { // Set some staging environment settings overrides. } elseif (Environment::isDevelopment()) { // Set some development environment settings overrides. } elseif (Environment::isLocal()) { // Set some development environment settings overrides. } // Redirect any internal platform domains to a preferred domain. if (Environment::isProduction()) { Environment::enforceDomain('www.example.com'); } // Include a environment-specific settings file. if ($environment = Environment::getEnvironment()) { $settings_file = 'settings.' . $environment . '.php'; if (is_file($settings_file)) { require_once $settings_file; } }
统计信息
- 总下载量: 240.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-24