..
This commit is contained in:
@@ -27,7 +27,7 @@ class CampusController extends AetherController
|
|||||||
/**
|
/**
|
||||||
* 校区列表.
|
* 校区列表.
|
||||||
*/
|
*/
|
||||||
#[GetMapping(path: '/campus/list')]
|
#[GetMapping(path: 'campus/list')]
|
||||||
public function list(RequestInterface $request): array
|
public function list(RequestInterface $request): array
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
@@ -77,7 +77,7 @@ class CampusController extends AetherController
|
|||||||
/**
|
/**
|
||||||
* 获取省份列表.
|
* 获取省份列表.
|
||||||
*/
|
*/
|
||||||
#[GetMapping(path: '/campus/provinces')]
|
#[GetMapping(path: 'campus/provinces')]
|
||||||
public function provinces(): array
|
public function provinces(): array
|
||||||
{
|
{
|
||||||
$provinces = Campus::level(1)
|
$provinces = Campus::level(1)
|
||||||
@@ -92,7 +92,7 @@ class CampusController extends AetherController
|
|||||||
/**
|
/**
|
||||||
* 获取城市列表.
|
* 获取城市列表.
|
||||||
*/
|
*/
|
||||||
#[GetMapping(path: '/campus/cities')]
|
#[GetMapping(path: 'campus/cities')]
|
||||||
public function cities(RequestInterface $request): array
|
public function cities(RequestInterface $request): array
|
||||||
{
|
{
|
||||||
$province = $request->input('province');
|
$province = $request->input('province');
|
||||||
@@ -113,7 +113,7 @@ class CampusController extends AetherController
|
|||||||
/**
|
/**
|
||||||
* 创建校区.
|
* 创建校区.
|
||||||
*/
|
*/
|
||||||
#[PostMapping(path: '/campus')]
|
#[PostMapping(path: 'campus')]
|
||||||
public function create(RequestInterface $request): array
|
public function create(RequestInterface $request): array
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
@@ -132,7 +132,7 @@ class CampusController extends AetherController
|
|||||||
/**
|
/**
|
||||||
* 获取校区详情.
|
* 获取校区详情.
|
||||||
*/
|
*/
|
||||||
#[GetMapping(path: '/campus/{id}')]
|
#[GetMapping(path: 'campus/{id}')]
|
||||||
public function get(int $id): array
|
public function get(int $id): array
|
||||||
{
|
{
|
||||||
$campus = Campus::find($id);
|
$campus = Campus::find($id);
|
||||||
@@ -146,7 +146,7 @@ class CampusController extends AetherController
|
|||||||
/**
|
/**
|
||||||
* 更新校区.
|
* 更新校区.
|
||||||
*/
|
*/
|
||||||
#[PutMapping(path: '/campus/{id}')]
|
#[PutMapping(path: 'campus/{id}')]
|
||||||
public function update(int $id, RequestInterface $request): array
|
public function update(int $id, RequestInterface $request): array
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
@@ -172,7 +172,7 @@ class CampusController extends AetherController
|
|||||||
* 删除校区.
|
* 删除校区.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
#[DeleteMapping(path: '/campus/{id}')]
|
#[DeleteMapping(path: 'campus/{id}')]
|
||||||
public function delete(int $id): array
|
public function delete(int $id): array
|
||||||
{
|
{
|
||||||
$campus = Campus::find($id);
|
$campus = Campus::find($id);
|
||||||
38
app/Exception/Handler/AppExceptionHandler.php
Normal file
38
app/Exception/Handler/AppExceptionHandler.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* This file is part of Hyperf.
|
||||||
|
*
|
||||||
|
* @link https://www.hyperf.io
|
||||||
|
* @document https://hyperf.wiki
|
||||||
|
* @contact group@hyperf.io
|
||||||
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Exception\Handler;
|
||||||
|
|
||||||
|
use Hyperf\Contract\StdoutLoggerInterface;
|
||||||
|
use Hyperf\ExceptionHandler\ExceptionHandler;
|
||||||
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class AppExceptionHandler extends ExceptionHandler
|
||||||
|
{
|
||||||
|
public function __construct(protected StdoutLoggerInterface $logger)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||||
|
{
|
||||||
|
$this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
|
||||||
|
$this->logger->error($throwable->getTraceAsString());
|
||||||
|
return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid(Throwable $throwable): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,8 @@ return [
|
|||||||
'handler' => [
|
'handler' => [
|
||||||
'http' => [
|
'http' => [
|
||||||
Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class,
|
Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class,
|
||||||
Aether\Exception\Handler\AppExceptionHandler::class,
|
App\Exception\Handler\AppExceptionHandler::class,
|
||||||
|
// Aether\Exception\Handler\AppExceptionHandler::class,
|
||||||
],
|
],
|
||||||
'jsonrpc-http' => [
|
'jsonrpc-http' => [
|
||||||
Aether\Exception\AppExceptionHandler::class,
|
Aether\Exception\AppExceptionHandler::class,
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
use Hyperf\HttpServer\Router\Router;
|
use Hyperf\HttpServer\Router\Router;
|
||||||
|
|
||||||
Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\IndexController@index');
|
// Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\IndexController@index');
|
||||||
|
//
|
||||||
|
// Router::get('/favicon.ico', function () {
|
||||||
|
// return '';
|
||||||
|
// });
|
||||||
|
|
||||||
Router::get('/favicon.ico', function () {
|
Router::get('/', function () {
|
||||||
return '';
|
return 'Hello World';
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user