app.php 6.5 KB

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