app.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Create The Application
  5. |--------------------------------------------------------------------------
  6. |
  7. | The first thing we will do is create a new Laravel application instance
  8. | which serves as the "glue" for all the components of Laravel, and is
  9. | the IoC container for the system binding all of the various parts.
  10. |
  11. */
  12. $app = new Illuminate\Foundation\Application(
  13. $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
  14. );
  15. /*
  16. |--------------------------------------------------------------------------
  17. | Bind Important Interfaces
  18. |--------------------------------------------------------------------------
  19. |
  20. | Next, we need to bind some important interfaces into the container so
  21. | we will be able to resolve them when needed. The kernels serve the
  22. | incoming requests to this application from both the web and CLI.
  23. |
  24. */
  25. $app->singleton(
  26. Illuminate\Contracts\Http\Kernel::class,
  27. App\Http\Kernel::class
  28. );
  29. $app->singleton(
  30. Illuminate\Contracts\Console\Kernel::class,
  31. App\Console\Kernel::class
  32. );
  33. $app->singleton(
  34. Illuminate\Contracts\Debug\ExceptionHandler::class,
  35. App\Exceptions\Handler::class
  36. );
  37. /*
  38. |--------------------------------------------------------------------------
  39. | Return The Application
  40. |--------------------------------------------------------------------------
  41. |
  42. | This script returns the application instance. The instance is given to
  43. | the calling script so we can separate the building of the instances
  44. | from the actual running of the application and sending responses.
  45. |
  46. */
  47. // 環境偵測(需要事先在 php.ini 中做好相關設定,若線上環境不支援修改則直接套用預設的 .env)
  48. $ore = 'pre';
  49. $compare = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : __DIR__;
  50. // 正式站新網址
  51. $ore = (str_replace('www.', '', $compare) != $compare) ? 'pro' : $ore;
  52. // 測試站
  53. $ore = (str_replace('demo.', '', $compare) != $compare) ? 'pre' : $ore;
  54. if(!defined('APP_MODE')){
  55. define('APP_MODE', $ore);
  56. }
  57. // $app->loadEnvironmentFrom('.env.'.$ore);
  58. $app->loadEnvironmentFrom('.env.pre');
  59. return $app;