响应对象 response
响应对象 Response 为 Swoft\Http\Message\Response
查看 response 对象源码,文件路径为 vendor/swoft/http-message/src/Response.php
class Response implements ResponseInterface
{
use CookiesTrait, MessageTrait, PrototypeTrait;
.
.
.
}
可知 response 对象实现了 ResponseInterface 接口,另外引用 CookiesTrait, MessageTrait, PrototypeTrait 三个trait
响应对象 response 的获取
- 通过控制器方法注入
- 通过请求上下文获取
<?php declare(strict_types=1);
namespace App\Http\Controller;
use Swoft\Context\Context;
use Swoft\Http\Message\ContentType;
use Swoft\Http\Message\Request;
use Swoft\Http\Message