app.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. ini_set('date.timezone', 'Asia/Shanghai');
  3. require_once __DIR__ . '/../vendor/autoload.php';
  4. $envFile = '.env';
  5. (new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
  6. dirname(__DIR__),
  7. $envFile
  8. ))->bootstrap();
  9. //try {
  10. // (new Dotenv\Dotenv(__DIR__ . '/../'))->load();
  11. //} catch (Dotenv\Exception\InvalidPathException $e) {
  12. // //
  13. //}
  14. /*
  15. |--------------------------------------------------------------------------
  16. | Create The Application
  17. |--------------------------------------------------------------------------
  18. |
  19. | Here we will load the environment and create the application instance
  20. | that serves as the central piece of this framework. We'll use this
  21. | application as an "IoC" container and router for this framework.
  22. |
  23. */
  24. $app = new Laravel\Lumen\Application(
  25. dirname(__DIR__)
  26. );
  27. $app->withFacades();
  28. //注册mongodb 必须在withEloquent之前
  29. //$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
  30. $app->withEloquent();
  31. /**
  32. * 缓存配置
  33. */
  34. $app->configure('app');
  35. $app->configure('auth');
  36. $app->configure('cache');
  37. /*
  38. |--------------------------------------------------------------------------
  39. | Register Container Bindings
  40. |--------------------------------------------------------------------------
  41. |
  42. | Now we will register a few bindings in the service container. We will
  43. | register the exception handler and the console kernel. You may add
  44. | your own bindings here if you like or you can make another file.
  45. |
  46. */
  47. $app->singleton(
  48. Illuminate\Contracts\Debug\ExceptionHandler::class, App\Base\Exceptions\Handler::class
  49. );
  50. $app->singleton(
  51. Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class
  52. );
  53. /*
  54. |--------------------------------------------------------------------------
  55. | Register Middleware
  56. |--------------------------------------------------------------------------
  57. |
  58. | Next, we will register the middleware with the application. These can
  59. | be global middleware that run before and after each request into a
  60. | route or middleware that'll be assigned to some specific routes.
  61. |
  62. */
  63. $app->middleware([
  64. //多语言
  65. App\Base\Middleware\Localization::class,
  66. //全局添加返回值格式
  67. App\Base\Middleware\Response::class
  68. ]);
  69. $app->routeMiddleware([
  70. 'auth' => App\Base\Middleware\Authenticate::class,
  71. 'permission' => App\Base\Middleware\Permission::class,
  72. 'api_permission' => App\Base\Middleware\ApiPermission::class,
  73. ]);
  74. /*
  75. |--------------------------------------------------------------------------
  76. | Register Service Providers
  77. |--------------------------------------------------------------------------
  78. |
  79. | Here we will register all of the application's service providers which
  80. | are used to bind services into the container. Service providers are
  81. | totally optional, so you are not required to uncomment this line.
  82. |
  83. */
  84. $getMillisecond = function () {
  85. list($t1, $t2) = explode(' ', microtime());
  86. return (float) sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
  87. };
  88. $app->register(App\Base\Providers\AppServiceProvider::class);
  89. $app->register(App\Base\Providers\EventServiceProvider::class);
  90. /*
  91. * 配置日志文件为每日
  92. */
  93. //
  94. //$app->configureMonologUsing(function(Monolog\Logger $monoLog) use ($app) {
  95. // return $monoLog->pushHandler(
  96. // new \Monolog\Handler\RotatingFileHandler($app->storagePath() . '/logs/lumen' . php_sapi_name() . '.log', 5)
  97. // );
  98. //});
  99. /*
  100. |--------------------------------------------------------------------------
  101. | Load The Application Routes
  102. |--------------------------------------------------------------------------
  103. |
  104. | Next we will include the routes file so that they can all be added to
  105. | the application. This will provide all of the URLs the application
  106. | can respond to, as well as the controllers that may handle them.
  107. |
  108. */
  109. return $app;