46 lines
918 B
PHP
46 lines
918 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Aether;
|
|
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\HttpServer\Contract\RequestInterface;
|
|
use Hyperf\HttpServer\Contract\ResponseInterface;
|
|
|
|
abstract class AetherController
|
|
{
|
|
#[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);
|
|
}
|
|
}
|