PHPackages                             davereid/drupal-environment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. davereid/drupal-environment

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

davereid/drupal-environment
===========================

Provides a helper for working with environment variables and Drupal hosting providers.

1.1.0(10mo ago)9274.2k↓44%2[6 issues](https://github.com/davereid/drupal-environment/issues)[2 PRs](https://github.com/davereid/drupal-environment/pulls)MITPHPPHP &gt;=8.1CI passing

Since Jun 27Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/davereid/drupal-environment)[ Packagist](https://packagist.org/packages/davereid/drupal-environment)[ RSS](/packages/davereid-drupal-environment/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (5)Dependencies (6)Versions (7)Used By (0)

Drupal Environment
==================

[](#drupal-environment)

[![CI](https://github.com/davereid/drupal-environment/actions/workflows/ci.yml/badge.svg)](https://github.com/davereid/drupal-environment/actions/workflows/ci.yml) [![Maintainability](https://camo.githubusercontent.com/b2a1a35a8fca61786c20405168b4051ba7963117347de057015dcbf573089282/68747470733a2f2f716c74792e73682f67682f64617665726569642f70726f6a656374732f64727570616c2d656e7669726f6e6d656e742f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/davereid/projects/drupal-environment) [![Code Coverage](https://camo.githubusercontent.com/246698cf4bff77045374484d0be1ba92fdb1fdbf23309806fa1d65cc8c80f829/68747470733a2f2f716c74792e73682f67682f64617665726569642f70726f6a656374732f64727570616c2d656e7669726f6e6d656e742f636f7665726167652e737667)](https://qlty.sh/gh/davereid/projects/drupal-environment) [![Packagist](https://camo.githubusercontent.com/bb3aca4f9aca0b665b7e676e886cfc899dc84942a2157195bdaf7e22d6a6e0c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64617665726569642f64727570616c2d656e7669726f6e6d656e742e737667)](https://packagist.org/packages/davereid/drupal-environment)

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:

EnvironmentAcquiaPantheonProduction`prod``live`Staging`test``test`Development`dev``dev`Basic Usage
-----------

[](#basic-usage)

### Getting an environment variable

[](#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

[](#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

[](#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

[](#testing-for-executable-commands)

```
use DrupalEnvironment\Environment;

// This returns a boolean true/false:
Environment::commandExists('composer');
```

Example usage
-------------

[](#example-usage)

### settings.php

[](#settingsphp)

```
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;
  }
}
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance42

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~198 days

Total

5

Last Release

309d ago

PHP version history (2 changes)1.0.0-beta1PHP &gt;=7.3

1.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f9825f5e52687732eb2ca7216f521b7de7953610aaca63d55d89005a843b1c2?d=identicon)[Dave Reid](/maintainers/Dave%20Reid)

---

Top Contributors

[![davereid](https://avatars.githubusercontent.com/u/62967?v=4)](https://github.com/davereid "davereid (47 commits)")[![davereid-pfg](https://avatars.githubusercontent.com/u/68073680?v=4)](https://github.com/davereid-pfg "davereid-pfg (46 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

drupalpantheonenvironmentacquiatugboat

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/davereid-drupal-environment/health.svg)

```
[![Health](https://phpackages.com/badges/davereid-drupal-environment/health.svg)](https://phpackages.com/packages/davereid-drupal-environment)
```

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k640.2M6.3k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k243.3M2.8k](/packages/symfony-dotenv)[lullabot/amp

A set of useful classes and utilities to convert html to AMP html (See https://www.ampproject.org/)

3793.0M11](/packages/lullabot-amp)[drupal/core-composer-scaffold

A flexible Composer project scaffold builder.

5445.2M565](/packages/drupal-core-composer-scaffold)[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1545.5M7](/packages/foroco-php-browser-detection)[mnsami/composer-custom-directory-installer

A composer plugin, to help install packages of different types in custom paths.

1465.4M62](/packages/mnsami-composer-custom-directory-installer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
