bootstrap.php 1015 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // Set environment variables
  3. test_suite_read_and_set_environment_variables();
  4. // Get Drupal root path
  5. $drupal_root = getenv('DRUPAL_ROOT');
  6. define('DRUPAL_ROOT', $drupal_root ?: '/var/www/html');
  7. // Get Drupal bootstrap functions
  8. require_once DRUPAL_ROOT.'/includes/bootstrap.inc';
  9. $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  10. // Bootstrap Drupal.
  11. $current_dir = getcwd();
  12. chdir(DRUPAL_ROOT);
  13. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  14. chdir($current_dir);
  15. /**
  16. * Get and set environment variables from .env file if it exists.
  17. *
  18. * @throws \Exception
  19. */
  20. function test_suite_read_and_set_environment_variables() {
  21. $filename = __DIR__.'/.env';
  22. if(file_exists($filename)) {
  23. $file = fopen($filename, 'r');
  24. while ($line = str_replace("\n", '', fgets($file))) {
  25. // break line into key value
  26. $env = explode('=', $line);
  27. if(count($env) === 2) {
  28. putenv($line);
  29. } else {
  30. throw new Exception('Invalid environment line: ' . $line);
  31. }
  32. }
  33. fclose($file);
  34. }
  35. }