Files
hyperf_data/extend/Aether/PHP/Hyperf/AetherController.php
Aether 485f59eac3 ..
2025-09-23 15:29:55 +08:00

50 lines
1018 B
PHP

<?php
declare(strict_types=1);
namespace Aether;
use Hyperf\Contract\ContainerInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
abstract class AetherController
{
#[Inject]
protected ContainerInterface $container;
#[Inject]
protected RequestInterface $request;
#[Inject]
protected ResponseInterface $response;
/**
* 获取请求参数.
* @param string $key
* @param mixed|null $default
* @return mixed
*/
public function requestParam(string $key, mixed $default = null): mixed
{
return $this->request->input($key, $default);
}
/**
* 获取所有请求参数.
*/
public function requestParams(): array
{
return $this->request->all();
}
/**
* 返回JSON响应.
*/
public function json(array $data): \Psr\Http\Message\ResponseInterface
{
return $this->response->json($data);
}
}