app.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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->withEloquent();
  31. /*
  32. |--------------------------------------------------------------------------
  33. | Register Container Bindings
  34. |--------------------------------------------------------------------------
  35. |
  36. | Now we will register a few bindings in the service container. We will
  37. | register the exception handler and the console kernel. You may add
  38. | your own bindings here if you like or you can make another file.
  39. |
  40. */
  41. $app->singleton(
  42. Illuminate\Contracts\Debug\ExceptionHandler::class,
  43. App\Exceptions\Handler::class
  44. );
  45. $app->singleton(
  46. Illuminate\Contracts\Console\Kernel::class,
  47. App\Console\Kernel::class
  48. );
  49. /*
  50. |--------------------------------------------------------------------------
  51. | Register Config Files
  52. |--------------------------------------------------------------------------
  53. |
  54. | Now we will register the "app" configuration file. If the file exists in
  55. | your configuration directory it will be loaded; otherwise, we'll load
  56. | the default version. You may register other files below as needed.
  57. |
  58. */
  59. $app->configure('app');
  60. $app->configure('auth');
  61. $app->configure('broadcasting');
  62. $app->configure('cache');
  63. $app->configure('database');
  64. $app->configure('filesystems');
  65. $app->configure('logging');
  66. $app->configure('queue');
  67. $app->configure('services');
  68. $app->configure('view');
  69. $app->configure('repository');
  70. $app->configure('enum');
  71. $app->configure('permission');
  72. $app->configure('response');
  73. $app->configure('site');
  74. $app->configure('wechat');
  75. $app->configure('sms');
  76. $app->configure('mail');
  77. $app->alias('cache', \Illuminate\Cache\CacheManager::class);
  78. /*
  79. |--------------------------------------------------------------------------
  80. | Register Middleware
  81. |--------------------------------------------------------------------------
  82. |
  83. | Next, we will register the middleware with the application. These can
  84. | be global middleware that run before and after each request into a
  85. | route or middleware that'll be assigned to some specific routes.
  86. |
  87. */
  88. // $app->middleware([
  89. // App\Http\Middleware\ExampleMiddleware::class
  90. // ]);
  91. $app->middleware([
  92. // \Jiannei\Logger\Laravel\Http\Middleware\RequestLog::class,
  93. \ZhMead\Logger\Laravel\Http\Middleware\RequestLog::class,
  94. \Jiannei\Response\Laravel\Http\Middleware\Etag::class,
  95. ]);
  96. $app->routeMiddleware([
  97. 'auth' => App\Http\Middleware\Authenticate::class,
  98. 'auth.api' => App\Http\Middleware\ApiAuthenticate::class,
  99. 'enum' => \Jiannei\Enum\Laravel\Http\Middleware\TransformEnums::class,
  100. 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
  101. 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
  102. 'throttle' => \Jiannei\Response\Laravel\Http\Middleware\ThrottleRequests::class,
  103. 'auth.role' => \App\Http\Middleware\JWTRoleAuth::class,
  104. 'checkUserPermission' => \App\Http\Middleware\CheckUserPermissionMiddleware::class,
  105. 'single' => \App\Http\Middleware\SingleLoginLimit::class,
  106. ]);
  107. /*
  108. |--------------------------------------------------------------------------
  109. | Register Service Providers
  110. |--------------------------------------------------------------------------
  111. |
  112. | Here we will register all of the application's service providers which
  113. | are used to bind services into the container. Service providers are
  114. | totally optional, so you are not required to uncomment this line.
  115. |
  116. */
  117. /*
  118. * Application Service Providers...
  119. */
  120. $app->register(App\Providers\AppServiceProvider::class);
  121. $app->register(App\Providers\AuthServiceProvider::class);
  122. $app->register(App\Providers\EventServiceProvider::class);
  123. /*
  124. * Package Service Providers...
  125. */
  126. $app->register(\Tymon\JWTAuth\Providers\LumenServiceProvider::class);
  127. $app->register(\Illuminate\Redis\RedisServiceProvider::class);
  128. $app->register(\Spatie\Permission\PermissionServiceProvider::class);
  129. $app->register(\Jiannei\Enum\Laravel\Providers\LumenServiceProvider::class);
  130. $app->register(\Jiannei\Response\Laravel\Providers\LumenServiceProvider::class);
  131. $app->register(\ZhMead\Logger\Laravel\LoggerServiceProvider::class);
  132. $app->register(ZhMead\LumenApiStarterGenerator\LumenGeneratorServiceProvider::class);
  133. $app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
  134. /*
  135. * Custom Service Providers.
  136. */
  137. $app->register(App\Providers\RepositoryServiceProvider::class);
  138. $app->register(\Maatwebsite\Excel\ExcelServiceProvider::class);
  139. /*
  140. |--------------------------------------------------------------------------
  141. | Load The Application Routes
  142. |--------------------------------------------------------------------------
  143. |
  144. | Next we will include the routes file so that they can all be added to
  145. | the application. This will provide all of the URLs the application
  146. | can respond to, as well as the controllers that may handle them.
  147. |
  148. */
  149. $app->router->group([
  150. 'namespace' => 'App\Http\Controllers',
  151. ], function ($router) {
  152. require __DIR__ . '/../routes/web.php';
  153. });
  154. $app->router->group([
  155. 'namespace' => 'App\Http\Controllers\Admin',
  156. 'prefix' => 'admin'
  157. ], function ($router) {
  158. require __DIR__ . '/../routes/admin.php';
  159. });
  160. $app->router->group([
  161. 'namespace' => 'App\Http\Controllers\Api',
  162. 'prefix' => 'api'
  163. ], function ($router) {
  164. require __DIR__ . '/../routes/api.php';
  165. });
  166. return $app;