2014-10-20 11:14:41 -05:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2025-05-12 00:19:35 +08:00
|
|
|
|
use App\Enum\ErrorEnum;
|
[11.x] Slim skeleton (#6188)
See: https://github.com/laravel/framework/pull/47309
# Laravel 11 Skeleton Overview
### General Notes
More environment variables have been added to the `.env.example` file.
The default `QUEUE_CONNECTION` variable value has been updated to `database` instead of `sync`.
The `BROADCAST_DRIVER` and `CACHE_DRIVER` environment variables have been renamed to `BROADCAST_CONNECTION` and `CACHE_STORE`, respectively.
The HTTP Kernel has been removed. Configuration that was previously done in this file can be done in the `bootstrap/app.php` file, including registering / replacing middleware.
The console kernel has been removed. Schedules can be defined in the console “routes” file. Commands generated by `make:command` are automatically loaded and do not require registration. Additional command loading paths can be registered in the `bootstrap/app.php` file.
The exception handler has been removed. Exception handling behavior can be configured in the `bootstrap/app.php` file via `reportable`, `renderable`, `throttle`, and more. Callbacks received by these functions will have their type hints inspected to see if they handle a given exception.
The base HTTP controller no longer extends any other classes (requiring new middleware definition feature). No traits are included by default on the base controller. Authorization can be done using facades, or traits can be added manually.
All middleware has been removed. Configuration of these middleware’s behavior can be done via static methods on the middleware themselves (see framework notes).
The `User` model now utilizes a `casts` method instead of a property. The `HasApiTokens` trait has been removed by default since Sanctum is not installed by default.
All service providers except the `AppServiceProvider` have been removed. Policies are auto-discovered and gates can be registered in `AppServiceProvider`. Likewise, events can be registered in `AppServiceProvider`. Routing behavior is now determined / customized in the `bootstrap/app.php` file.
New `bootstrap/app.php` file can be used to customize core framework behavior like routing, container bindings, middleware, and exception handling.
Sanctum is no longer installed by default (see `install:api`).
Configuration files are not present by default. Can be published by `config:publish` command. Default values are present in the framework and application level configuration now cascades with framework definitions, so only customized values need be present in application level configuration files.
Migration files have been re-dated to be evergreen. The `password_reset_tokens` table migration has been combined into the `users` table migration file. Likewise, the `jobs` table migration has been combined into a single migration with the `failed_jobs` table.
Echo bootstrapping has been removed by default. It is re-inserted by new `install:broadcasting` command.
API and channel routes files are not present by default, can be recreated by `install:api` and `install:broadcasting` respectively.
2023-11-28 14:28:15 -06:00
|
|
|
|
use Illuminate\Foundation\Application;
|
|
|
|
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
|
|
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
2025-05-12 00:19:35 +08:00
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
[11.x] Slim skeleton (#6188)
See: https://github.com/laravel/framework/pull/47309
# Laravel 11 Skeleton Overview
### General Notes
More environment variables have been added to the `.env.example` file.
The default `QUEUE_CONNECTION` variable value has been updated to `database` instead of `sync`.
The `BROADCAST_DRIVER` and `CACHE_DRIVER` environment variables have been renamed to `BROADCAST_CONNECTION` and `CACHE_STORE`, respectively.
The HTTP Kernel has been removed. Configuration that was previously done in this file can be done in the `bootstrap/app.php` file, including registering / replacing middleware.
The console kernel has been removed. Schedules can be defined in the console “routes” file. Commands generated by `make:command` are automatically loaded and do not require registration. Additional command loading paths can be registered in the `bootstrap/app.php` file.
The exception handler has been removed. Exception handling behavior can be configured in the `bootstrap/app.php` file via `reportable`, `renderable`, `throttle`, and more. Callbacks received by these functions will have their type hints inspected to see if they handle a given exception.
The base HTTP controller no longer extends any other classes (requiring new middleware definition feature). No traits are included by default on the base controller. Authorization can be done using facades, or traits can be added manually.
All middleware has been removed. Configuration of these middleware’s behavior can be done via static methods on the middleware themselves (see framework notes).
The `User` model now utilizes a `casts` method instead of a property. The `HasApiTokens` trait has been removed by default since Sanctum is not installed by default.
All service providers except the `AppServiceProvider` have been removed. Policies are auto-discovered and gates can be registered in `AppServiceProvider`. Likewise, events can be registered in `AppServiceProvider`. Routing behavior is now determined / customized in the `bootstrap/app.php` file.
New `bootstrap/app.php` file can be used to customize core framework behavior like routing, container bindings, middleware, and exception handling.
Sanctum is no longer installed by default (see `install:api`).
Configuration files are not present by default. Can be published by `config:publish` command. Default values are present in the framework and application level configuration now cascades with framework definitions, so only customized values need be present in application level configuration files.
Migration files have been re-dated to be evergreen. The `password_reset_tokens` table migration has been combined into the `users` table migration file. Likewise, the `jobs` table migration has been combined into a single migration with the `failed_jobs` table.
Echo bootstrapping has been removed by default. It is re-inserted by new `install:broadcasting` command.
API and channel routes files are not present by default, can be recreated by `install:api` and `install:broadcasting` respectively.
2023-11-28 14:28:15 -06:00
|
|
|
|
|
2024-01-21 15:49:03 -06:00
|
|
|
|
return Application::configure(basePath: dirname(__DIR__))
|
[11.x] Slim skeleton (#6188)
See: https://github.com/laravel/framework/pull/47309
# Laravel 11 Skeleton Overview
### General Notes
More environment variables have been added to the `.env.example` file.
The default `QUEUE_CONNECTION` variable value has been updated to `database` instead of `sync`.
The `BROADCAST_DRIVER` and `CACHE_DRIVER` environment variables have been renamed to `BROADCAST_CONNECTION` and `CACHE_STORE`, respectively.
The HTTP Kernel has been removed. Configuration that was previously done in this file can be done in the `bootstrap/app.php` file, including registering / replacing middleware.
The console kernel has been removed. Schedules can be defined in the console “routes” file. Commands generated by `make:command` are automatically loaded and do not require registration. Additional command loading paths can be registered in the `bootstrap/app.php` file.
The exception handler has been removed. Exception handling behavior can be configured in the `bootstrap/app.php` file via `reportable`, `renderable`, `throttle`, and more. Callbacks received by these functions will have their type hints inspected to see if they handle a given exception.
The base HTTP controller no longer extends any other classes (requiring new middleware definition feature). No traits are included by default on the base controller. Authorization can be done using facades, or traits can be added manually.
All middleware has been removed. Configuration of these middleware’s behavior can be done via static methods on the middleware themselves (see framework notes).
The `User` model now utilizes a `casts` method instead of a property. The `HasApiTokens` trait has been removed by default since Sanctum is not installed by default.
All service providers except the `AppServiceProvider` have been removed. Policies are auto-discovered and gates can be registered in `AppServiceProvider`. Likewise, events can be registered in `AppServiceProvider`. Routing behavior is now determined / customized in the `bootstrap/app.php` file.
New `bootstrap/app.php` file can be used to customize core framework behavior like routing, container bindings, middleware, and exception handling.
Sanctum is no longer installed by default (see `install:api`).
Configuration files are not present by default. Can be published by `config:publish` command. Default values are present in the framework and application level configuration now cascades with framework definitions, so only customized values need be present in application level configuration files.
Migration files have been re-dated to be evergreen. The `password_reset_tokens` table migration has been combined into the `users` table migration file. Likewise, the `jobs` table migration has been combined into a single migration with the `failed_jobs` table.
Echo bootstrapping has been removed by default. It is re-inserted by new `install:broadcasting` command.
API and channel routes files are not present by default, can be recreated by `install:api` and `install:broadcasting` respectively.
2023-11-28 14:28:15 -06:00
|
|
|
|
->withRouting(
|
|
|
|
|
|
web: __DIR__.'/../routes/web.php',
|
2025-05-12 00:19:35 +08:00
|
|
|
|
api: __DIR__.'/../routes/api.php',
|
[11.x] Slim skeleton (#6188)
See: https://github.com/laravel/framework/pull/47309
# Laravel 11 Skeleton Overview
### General Notes
More environment variables have been added to the `.env.example` file.
The default `QUEUE_CONNECTION` variable value has been updated to `database` instead of `sync`.
The `BROADCAST_DRIVER` and `CACHE_DRIVER` environment variables have been renamed to `BROADCAST_CONNECTION` and `CACHE_STORE`, respectively.
The HTTP Kernel has been removed. Configuration that was previously done in this file can be done in the `bootstrap/app.php` file, including registering / replacing middleware.
The console kernel has been removed. Schedules can be defined in the console “routes” file. Commands generated by `make:command` are automatically loaded and do not require registration. Additional command loading paths can be registered in the `bootstrap/app.php` file.
The exception handler has been removed. Exception handling behavior can be configured in the `bootstrap/app.php` file via `reportable`, `renderable`, `throttle`, and more. Callbacks received by these functions will have their type hints inspected to see if they handle a given exception.
The base HTTP controller no longer extends any other classes (requiring new middleware definition feature). No traits are included by default on the base controller. Authorization can be done using facades, or traits can be added manually.
All middleware has been removed. Configuration of these middleware’s behavior can be done via static methods on the middleware themselves (see framework notes).
The `User` model now utilizes a `casts` method instead of a property. The `HasApiTokens` trait has been removed by default since Sanctum is not installed by default.
All service providers except the `AppServiceProvider` have been removed. Policies are auto-discovered and gates can be registered in `AppServiceProvider`. Likewise, events can be registered in `AppServiceProvider`. Routing behavior is now determined / customized in the `bootstrap/app.php` file.
New `bootstrap/app.php` file can be used to customize core framework behavior like routing, container bindings, middleware, and exception handling.
Sanctum is no longer installed by default (see `install:api`).
Configuration files are not present by default. Can be published by `config:publish` command. Default values are present in the framework and application level configuration now cascades with framework definitions, so only customized values need be present in application level configuration files.
Migration files have been re-dated to be evergreen. The `password_reset_tokens` table migration has been combined into the `users` table migration file. Likewise, the `jobs` table migration has been combined into a single migration with the `failed_jobs` table.
Echo bootstrapping has been removed by default. It is re-inserted by new `install:broadcasting` command.
API and channel routes files are not present by default, can be recreated by `install:api` and `install:broadcasting` respectively.
2023-11-28 14:28:15 -06:00
|
|
|
|
commands: __DIR__.'/../routes/console.php',
|
2024-01-24 15:15:09 -06:00
|
|
|
|
health: '/up',
|
[11.x] Slim skeleton (#6188)
See: https://github.com/laravel/framework/pull/47309
# Laravel 11 Skeleton Overview
### General Notes
More environment variables have been added to the `.env.example` file.
The default `QUEUE_CONNECTION` variable value has been updated to `database` instead of `sync`.
The `BROADCAST_DRIVER` and `CACHE_DRIVER` environment variables have been renamed to `BROADCAST_CONNECTION` and `CACHE_STORE`, respectively.
The HTTP Kernel has been removed. Configuration that was previously done in this file can be done in the `bootstrap/app.php` file, including registering / replacing middleware.
The console kernel has been removed. Schedules can be defined in the console “routes” file. Commands generated by `make:command` are automatically loaded and do not require registration. Additional command loading paths can be registered in the `bootstrap/app.php` file.
The exception handler has been removed. Exception handling behavior can be configured in the `bootstrap/app.php` file via `reportable`, `renderable`, `throttle`, and more. Callbacks received by these functions will have their type hints inspected to see if they handle a given exception.
The base HTTP controller no longer extends any other classes (requiring new middleware definition feature). No traits are included by default on the base controller. Authorization can be done using facades, or traits can be added manually.
All middleware has been removed. Configuration of these middleware’s behavior can be done via static methods on the middleware themselves (see framework notes).
The `User` model now utilizes a `casts` method instead of a property. The `HasApiTokens` trait has been removed by default since Sanctum is not installed by default.
All service providers except the `AppServiceProvider` have been removed. Policies are auto-discovered and gates can be registered in `AppServiceProvider`. Likewise, events can be registered in `AppServiceProvider`. Routing behavior is now determined / customized in the `bootstrap/app.php` file.
New `bootstrap/app.php` file can be used to customize core framework behavior like routing, container bindings, middleware, and exception handling.
Sanctum is no longer installed by default (see `install:api`).
Configuration files are not present by default. Can be published by `config:publish` command. Default values are present in the framework and application level configuration now cascades with framework definitions, so only customized values need be present in application level configuration files.
Migration files have been re-dated to be evergreen. The `password_reset_tokens` table migration has been combined into the `users` table migration file. Likewise, the `jobs` table migration has been combined into a single migration with the `failed_jobs` table.
Echo bootstrapping has been removed by default. It is re-inserted by new `install:broadcasting` command.
API and channel routes files are not present by default, can be recreated by `install:api` and `install:broadcasting` respectively.
2023-11-28 14:28:15 -06:00
|
|
|
|
)
|
|
|
|
|
|
->withMiddleware(function (Middleware $middleware) {
|
|
|
|
|
|
//
|
|
|
|
|
|
})
|
|
|
|
|
|
->withExceptions(function (Exceptions $exceptions) {
|
2025-05-12 00:19:35 +08:00
|
|
|
|
$exceptions->render(function (Throwable $e) {
|
|
|
|
|
|
// 判断异常是否为Exception类型
|
|
|
|
|
|
if ($e instanceof \Exception) {
|
|
|
|
|
|
// \App\Models\new\log\ErrorLogModel::create([
|
|
|
|
|
|
// 'type' => 0,
|
|
|
|
|
|
// 'content' => json_encode([
|
|
|
|
|
|
// 'message' => $e->getMessage(),
|
|
|
|
|
|
// 'line' => $e->getLine(),
|
|
|
|
|
|
// 'file' => $e->getFile(),
|
|
|
|
|
|
// 'trace' => $e->getTraceAsString(),
|
|
|
|
|
|
// ]),
|
|
|
|
|
|
// 'created_at' => time()
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
// 使用switch语句判断异常类型
|
|
|
|
|
|
switch (true) { // 注意这里使用了 'true' 因为 PHP 不允许在 case 中使用表达式
|
|
|
|
|
|
// 如果异常是NotFoundHttpException类型
|
|
|
|
|
|
case $e instanceof NotFoundHttpException:
|
|
|
|
|
|
// 返回一个自定义的JSON响应,状态码为404,错误信息为"路由未找到"
|
|
|
|
|
|
return jInstanceof(ErrorEnum::NOT_FOUND, '路由未找到', $e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
// 如果异常是MethodNotAllowedHttpException类型
|
|
|
|
|
|
case $e instanceof MethodNotAllowedHttpException:
|
|
|
|
|
|
Log::error($e->getMessage());
|
|
|
|
|
|
// 返回一个自定义的JSON响应,状态码为405,错误信息为"请求方式错误"
|
|
|
|
|
|
return jInstanceof(405, '请求方式错误', $e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
// 如果异常是UnprocessableEntityHttpException类型
|
|
|
|
|
|
case $e instanceof UnprocessableEntityHttpException:
|
|
|
|
|
|
Log::warning($e->getMessage());
|
|
|
|
|
|
// 返回一个自定义的JSON响应,状态码为422,错误信息为"服务器处理不过来啦"
|
|
|
|
|
|
return jInstanceof(422, '服务器处理不过来啦', $e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
// // 如果异常是HttpException类型
|
|
|
|
|
|
// case $e instanceof HttpException:
|
|
|
|
|
|
// Log::error($e->getMessage());
|
|
|
|
|
|
// // 返回一个自定义的JSON响应,状态码为异常的状态码,错误信息为"服务器出错啦"
|
|
|
|
|
|
// return jInstanceof($e->getCode(), ErrorEnum::FAIL->description(), 'ERROR:'. $e->getMessage());
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 对于所有其他类型的异常,默认返回500内部服务器错误
|
|
|
|
|
|
default:
|
|
|
|
|
|
Log::critical($e->getMessage()); // 记录更严重的日志级别
|
|
|
|
|
|
// 返回一个自定义的JSON响应,状态码为500,错误信息为"内部服务器错误"
|
|
|
|
|
|
return jInstanceof($e->getCode(), $e->getMessage(), $e->getCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return jInstanceof(ErrorEnum::FAIL, '服务器出错啦~', [
|
|
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
|
|
'code' => $e->getCode(),
|
|
|
|
|
|
'file' => $e->getFile(),
|
|
|
|
|
|
'line' => $e->getLine(),
|
|
|
|
|
|
'trace' => $e->getTrace(),
|
|
|
|
|
|
]);
|
|
|
|
|
|
});
|
[11.x] Slim skeleton (#6188)
See: https://github.com/laravel/framework/pull/47309
# Laravel 11 Skeleton Overview
### General Notes
More environment variables have been added to the `.env.example` file.
The default `QUEUE_CONNECTION` variable value has been updated to `database` instead of `sync`.
The `BROADCAST_DRIVER` and `CACHE_DRIVER` environment variables have been renamed to `BROADCAST_CONNECTION` and `CACHE_STORE`, respectively.
The HTTP Kernel has been removed. Configuration that was previously done in this file can be done in the `bootstrap/app.php` file, including registering / replacing middleware.
The console kernel has been removed. Schedules can be defined in the console “routes” file. Commands generated by `make:command` are automatically loaded and do not require registration. Additional command loading paths can be registered in the `bootstrap/app.php` file.
The exception handler has been removed. Exception handling behavior can be configured in the `bootstrap/app.php` file via `reportable`, `renderable`, `throttle`, and more. Callbacks received by these functions will have their type hints inspected to see if they handle a given exception.
The base HTTP controller no longer extends any other classes (requiring new middleware definition feature). No traits are included by default on the base controller. Authorization can be done using facades, or traits can be added manually.
All middleware has been removed. Configuration of these middleware’s behavior can be done via static methods on the middleware themselves (see framework notes).
The `User` model now utilizes a `casts` method instead of a property. The `HasApiTokens` trait has been removed by default since Sanctum is not installed by default.
All service providers except the `AppServiceProvider` have been removed. Policies are auto-discovered and gates can be registered in `AppServiceProvider`. Likewise, events can be registered in `AppServiceProvider`. Routing behavior is now determined / customized in the `bootstrap/app.php` file.
New `bootstrap/app.php` file can be used to customize core framework behavior like routing, container bindings, middleware, and exception handling.
Sanctum is no longer installed by default (see `install:api`).
Configuration files are not present by default. Can be published by `config:publish` command. Default values are present in the framework and application level configuration now cascades with framework definitions, so only customized values need be present in application level configuration files.
Migration files have been re-dated to be evergreen. The `password_reset_tokens` table migration has been combined into the `users` table migration file. Likewise, the `jobs` table migration has been combined into a single migration with the `failed_jobs` table.
Echo bootstrapping has been removed by default. It is re-inserted by new `install:broadcasting` command.
API and channel routes files are not present by default, can be recreated by `install:api` and `install:broadcasting` respectively.
2023-11-28 14:28:15 -06:00
|
|
|
|
})->create();
|