💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 请求对象 此页面参照了EasySwoole Distributed的文档,原文档地址 [https://www.kancloud.cn/tmtbe/goswoole/1107125]: https://www.kancloud.cn/tmtbe/goswoole/1107125 当前的请求对象由`ESD\Core\Server\Beans\AbstractRequest`类负责,该类不需要单独实例化调用,通常使用依赖注入即可。在其它场合则可以使用`trait GetHttp`操作。 ## 构造方法注入 一般适用于没有继承系统的控制器类的情况。request 对象符合psr-7规范。 ```php <?php namespace ESD\Examples\Controller; use DI\Annotation\Inject; use ESD\Core\Server\Beans\Request; use ESD\Plugins\EasyRoute\Annotation\RestController; /** * @RestController() * Class IndexContoller */ class IndexController extends GoController { /** * @Inject() * @var Request */ public $request; public function actionParams(){ return $this->request->query(); } ``` ## trait 引入 ```php use \ESD\Plugins\EasyRoute\GetHttp; public function params(){ $this->getRequest(); //获取psr-7对象 //以下方法为trait进行了一些封装 $this->query(); $this->queryRequire(); $this->post(); $this->postRequire(); $this->postRawJson(); $this->postRawXml(); $this->input(); $this->inputRequire(); } ``` ## 直接调用 ```php getDeepContextValueByClassName(Request::class); ```