app.php 5.9 KB

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