app.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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('PRC');
  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->configure('excel');
  78. $app->alias('cache', \Illuminate\Cache\CacheManager::class);
  79. $app->alias('image', Intervention\Image\Facades\Image::class);
  80. /*
  81. |--------------------------------------------------------------------------
  82. | Register Middleware
  83. |--------------------------------------------------------------------------
  84. |
  85. | Next, we will register the middleware with the application. These can
  86. | be global middleware that run before and after each request into a
  87. | route or middleware that'll be assigned to some specific routes.
  88. |
  89. */
  90. // $app->middleware([
  91. // App\Http\Middleware\ExampleMiddleware::class
  92. // ]);
  93. $app->middleware([
  94. \ZhMead\Logger\Laravel\Http\Middleware\RequestLog::class,
  95. // \Jiannei\Response\Laravel\Http\Middleware\Etag::class,
  96. ]);
  97. $app->routeMiddleware([
  98. 'auth' => App\Http\Middleware\Authenticate::class,
  99. 'auth.api' => App\Http\Middleware\ApiAuthenticate::class,
  100. 'enum' => \Jiannei\Enum\Laravel\Http\Middleware\TransformEnums::class,
  101. 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
  102. 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
  103. 'throttle' => \Jiannei\Response\Laravel\Http\Middleware\ThrottleRequests::class,
  104. 'auth.role' => \App\Http\Middleware\JWTRoleAuth::class,
  105. 'checkUserPermission' => \App\Http\Middleware\CheckUserPermissionMiddleware::class,
  106. 'single' => \App\Http\Middleware\SingleLoginLimit::class,
  107. ]);
  108. /*
  109. |--------------------------------------------------------------------------
  110. | Register Service Providers
  111. |--------------------------------------------------------------------------
  112. |
  113. | Here we will register all of the application's service providers which
  114. | are used to bind services into the container. Service providers are
  115. | totally optional, so you are not required to uncomment this line.
  116. |
  117. */
  118. /*
  119. * Application Service Providers...
  120. */
  121. $app->register(App\Providers\AppServiceProvider::class);
  122. $app->register(App\Providers\AuthServiceProvider::class);
  123. $app->register(App\Providers\EventServiceProvider::class);
  124. /*
  125. * Package Service Providers...
  126. */
  127. $app->register(\Tymon\JWTAuth\Providers\LumenServiceProvider::class);
  128. $app->register(\Illuminate\Redis\RedisServiceProvider::class);
  129. $app->register(\Spatie\Permission\PermissionServiceProvider::class);
  130. $app->register(\Jiannei\Enum\Laravel\Providers\LumenServiceProvider::class);
  131. $app->register(\Jiannei\Response\Laravel\Providers\LumenServiceProvider::class);
  132. $app->register(\ZhMead\Logger\Laravel\LoggerServiceProvider::class);
  133. $app->register(ZhMead\LumenApiStarterGenerator\LumenGeneratorServiceProvider::class);
  134. $app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
  135. /*
  136. * Custom Service Providers.
  137. */
  138. $app->register(App\Providers\RepositoryServiceProvider::class);
  139. $app->register(\Maatwebsite\Excel\ExcelServiceProvider::class);
  140. $app->register(SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class);
  141. $app->register(Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider::class);
  142. $app->register(Intervention\Image\ImageServiceProvider::class);
  143. //$app->register(\Vinkla\Hashids\HashidsServiceProvider::class);
  144. /*
  145. |--------------------------------------------------------------------------
  146. | Load The Application Routes
  147. |--------------------------------------------------------------------------
  148. |
  149. | Next we will include the routes file so that they can all be added to
  150. | the application. This will provide all of the URLs the application
  151. | can respond to, as well as the controllers that may handle them.
  152. |
  153. */
  154. $app->router->group([
  155. 'namespace' => 'App\Http\Controllers',
  156. ], function ($router) {
  157. require __DIR__ . '/../routes/web.php';
  158. });
  159. $app->router->group([
  160. 'namespace' => 'App\Http\Controllers\Admin',
  161. 'prefix' => 'admin',
  162. ], function ($router) {
  163. require __DIR__ . '/../routes/admin.php';
  164. });
  165. $app->router->group([
  166. 'namespace' => 'App\Http\Controllers\Api',
  167. 'prefix' => 'api'
  168. ], function ($router) {
  169. require __DIR__ . '/../routes/api.php';
  170. });
  171. return $app;