app.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. require_once __DIR__ . '/../vendor/autoload.php';
  11. (new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
  12. dirname(__DIR__)
  13. ))->bootstrap();
  14. date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
  15. /*
  16. |--------------------------------------------------------------------------
  17. | Create The Application
  18. |--------------------------------------------------------------------------
  19. |
  20. | Here we will load the environment and create the application instance
  21. | that serves as the central piece of this framework. We'll use this
  22. | application as an "IoC" container and router for this framework.
  23. |
  24. */
  25. $app = new Laravel\Lumen\Application(
  26. dirname(__DIR__)
  27. );
  28. $app->withFacades();
  29. $app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
  30. $app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
  31. $app->register(Overtrue\LaravelPinyin\ServiceProvider::class);
  32. $app->withEloquent();
  33. /*
  34. |--------------------------------------------------------------------------
  35. | Register Container Bindings
  36. |--------------------------------------------------------------------------
  37. |
  38. | Now we will register a few bindings in the service container. We will
  39. | register the exception handler and the console kernel. You may add
  40. | your own bindings here if you like or you can make another file.
  41. |
  42. */
  43. $app->singleton(
  44. Illuminate\Contracts\Debug\ExceptionHandler::class,
  45. App\Exceptions\Handler::class
  46. );
  47. $app->singleton(
  48. Illuminate\Contracts\Console\Kernel::class,
  49. App\Console\Kernel::class
  50. );
  51. /*
  52. |--------------------------------------------------------------------------
  53. | Register Config Files
  54. |--------------------------------------------------------------------------
  55. |
  56. | Now we will register the "app" configuration file. If the file exists in
  57. | your configuration directory it will be loaded; otherwise, we'll load
  58. | the default version. You may register other files below as needed.
  59. |
  60. */
  61. $app->configure('app');
  62. $app->configure('auth');
  63. $app->configure('broadcasting');
  64. $app->configure('cache');
  65. $app->configure('database');
  66. $app->configure('filesystems');
  67. $app->configure('logging');
  68. $app->configure('queue');
  69. $app->configure('services');
  70. $app->configure('view');
  71. $app->configure('repository');
  72. $app->configure('enum');
  73. $app->configure('permission');
  74. $app->configure('response');
  75. $app->alias('cache', \Illuminate\Cache\CacheManager::class);
  76. /*
  77. |--------------------------------------------------------------------------
  78. | Register Middleware
  79. |--------------------------------------------------------------------------
  80. |
  81. | Next, we will register the middleware with the application. These can
  82. | be global middleware that run before and after each request into a
  83. | route or middleware that'll be assigned to some specific routes.
  84. |
  85. */
  86. // $app->middleware([
  87. // App\Http\Middleware\ExampleMiddleware::class
  88. // ]);
  89. $app->middleware([
  90. \Jiannei\Logger\Laravel\Http\Middleware\RequestLog::class,
  91. \Jiannei\Response\Laravel\Http\Middleware\Etag::class,
  92. \App\Http\Middleware\Language::class,
  93. \App\Http\Middleware\CorsMiddleware::class
  94. ]);
  95. $app->routeMiddleware([
  96. 'auth' => App\Http\Middleware\Authenticate::class,
  97. 'enum' => \Jiannei\Enum\Laravel\Http\Middleware\TransformEnums::class,
  98. 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
  99. 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
  100. 'throttle' => \Jiannei\Response\Laravel\Http\Middleware\ThrottleRequests::class,
  101. ]);
  102. /*
  103. |--------------------------------------------------------------------------
  104. | Register Service Providers
  105. |--------------------------------------------------------------------------
  106. |
  107. | Here we will register all of the application's service providers which
  108. | are used to bind services into the container. Service providers are
  109. | totally optional, so you are not required to uncomment this line.
  110. |
  111. */
  112. /*
  113. * Application Service Providers...
  114. */
  115. $app->register(App\Providers\AppServiceProvider::class);
  116. $app->register(App\Providers\AuthServiceProvider::class);
  117. $app->register(App\Providers\EventServiceProvider::class);
  118. /*
  119. * Package Service Providers...
  120. */
  121. $app->register(\Tymon\JWTAuth\Providers\LumenServiceProvider::class);
  122. $app->register(\Illuminate\Redis\RedisServiceProvider::class);
  123. $app->register(\Spatie\Permission\PermissionServiceProvider::class);
  124. $app->register(\Jiannei\Enum\Laravel\Providers\LumenServiceProvider::class);
  125. $app->register(\Jiannei\Response\Laravel\Providers\LumenServiceProvider::class);
  126. $app->register(\Jiannei\Logger\Laravel\Providers\ServiceProvider::class);
  127. /*
  128. * Custom Service Providers.
  129. */
  130. $app->register(App\Providers\RepositoryServiceProvider::class);
  131. //$app->register(Prettus\Repository\Providers\LumenRepositoryServiceProvider::class);
  132. //$app->register(Prettus\Repository\Providers\RepositoryServiceProvider::class);
  133. $app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
  134. $app->register(\Maatwebsite\Excel\ExcelServiceProvider::class);
  135. /*
  136. |--------------------------------------------------------------------------
  137. | Load The Application Routes
  138. |--------------------------------------------------------------------------
  139. |
  140. | Next we will include the routes file so that they can all be added to
  141. | the application. This will provide all of the URLs the application
  142. | can respond to, as well as the controllers that may handle them.
  143. |
  144. */
  145. $app->router->group([
  146. 'namespace' => 'App\Http\Controllers\Admin',
  147. ], function ($router) {
  148. require __DIR__ . '/../routes/admin.php';
  149. });
  150. return $app;