yii 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * Yii console bootstrap file.
  5. *
  6. * @link http://www.yiiframework.com/
  7. * @copyright Copyright (c) 2008 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. const DS = DIRECTORY_SEPARATOR;
  11. defined('YII_DEBUG') or define('YII_DEBUG', true);
  12. defined('YII_ENV') or define('YII_ENV', 'dev');
  13. require __DIR__ . '/vendor/autoload.php';
  14. require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
  15. $env='prod';
  16. $env_file = __DIR__ .DS.'.env';
  17. if (file_exists($env_file)) {
  18. $env = [];
  19. $lines = explode(PHP_EOL,trim(file_get_contents($env_file)));
  20. foreach ($lines as $line){
  21. $pair = explode("=",$line);
  22. $env[$pair[0]]=$pair[1];
  23. defined($pair[0]) or define($pair[0], $pair[1]);
  24. }
  25. if(\yii\helpers\ArrayHelper::getValue($env,'ENV',false) && $env['ENV']=="dev"){
  26. $env = "dev";
  27. defined('YII_DEBUG') or define('YII_DEBUG', true);
  28. defined('YII_ENV') or define('YII_ENV', 'dev');
  29. defined('YII_ENV_DEV') or define('YII_ENV_DEV', 'dev');
  30. }
  31. if(isset($env['ENV'])){
  32. $env = $env['ENV'];
  33. } else{
  34. $env = "prod";
  35. }
  36. } else {
  37. defined('YII_DEBUG') or define('YII_DEBUG', false);
  38. defined('YII_ENV') or define('YII_ENV', 'prod');
  39. }
  40. $config_path = __DIR__ . DS.'config'.DS.'console.php';
  41. $config = require($config_path);
  42. $application = new yii\console\Application($config);
  43. $exitCode = $application->run();
  44. exit($exitCode);