PHP code example of davereid / drupal-environment

1. Go to this page and download the library: Download davereid/drupal-environment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

davereid / drupal-environment example snippets


use DrupalEnvironment\Environment;
$value = Environment::get('VARIABLE_NAME');

use DrupalEnvironment\Environment;

// These all return a boolean true/false
Environment::isPantheon();
Environment::isAcquia();
Environment::isTugboat();
Environment::isGitHubWorkflow();
Environment::isGitLabCi();
Environment::isCircleCi();

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();

use DrupalEnvironment\Environment;

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

use DrupalEnvironment\Environment;

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.
}

// Include a environment-specific settings file.
if ($environment = Environment::getEnvironment()) {
  $settings_file = 'settings.' . $environment . '.php';
  if (is_file($settings_file)) {