index.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. const DS = DIRECTORY_SEPARATOR;
  3. // comment out the following two lines when deployed to production
  4. defined('YII_DEBUG') or define('YII_DEBUG', true);
  5. defined('YII_ENV') or define('YII_ENV', 'dev');
  6. require __DIR__ . '/../vendor/autoload.php';
  7. require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
  8. $env='prod';
  9. $env_file = __DIR__ . DS . '..' . DS . '.env';
  10. if (file_exists($env_file)) {
  11. $env_content = trim(file_get_contents($env_file));
  12. $parameters_pairs = explode("\r\n", $env_content);
  13. $params = [];
  14. $env = [];
  15. $lines = explode(PHP_EOL,trim(file_get_contents($env_file)));
  16. foreach ($lines as $line){
  17. $pair = explode("=",$line);
  18. $env[$pair[0]]=$pair[1];
  19. defined($pair[0]) or define($pair[0], $pair[1]);
  20. }
  21. if(\yii\helpers\ArrayHelper::getValue($env,'ENV',false) && $env['ENV']=="dev"){
  22. $env = "dev";
  23. defined('YII_DEBUG') or define('YII_DEBUG', true);
  24. defined('YII_ENV') or define('YII_ENV', 'dev');
  25. defined('YII_ENV_DEV') or define('YII_ENV_DEV', 'dev');
  26. }
  27. if(isset($env['ENV'])){
  28. $env = $env['ENV'];
  29. } else {
  30. $env = "prod";
  31. }
  32. } else {
  33. defined('YII_DEBUG') or define('YII_DEBUG', false);
  34. defined('YII_ENV') or define('YII_ENV', 'prod');
  35. }
  36. if (file_exists(__DIR__ . DS . '..' . DS . 'revision.php')) {
  37. require_once(__DIR__ . DS . '..' . DS . 'revision.php');
  38. }
  39. if (!defined('REV')) {
  40. define('REV', 1);
  41. }
  42. $config_path = __DIR__ . DS.'..'.DS.'config'.DS.'env'.DS.$env.'.php';
  43. $config = require($config_path);
  44. $config = require __DIR__ . '/../config/web.php';
  45. (new yii\web\Application($config))->run();