這里寫問題描述
代碼:
dump(Container::make(Response::class,
[
200,
['Content-Type' => 'application/json'],
json_encode(['code'=>0,'msg'=>'ok'],JSON_UNESCAPED_UNICODE)
] ));
打印出來的值
^ support\Response^ {#73
#exception: null
#_header: []
#_status: 200
#_reason: null
#_version: "1.1"
#_body: ""
+file: null
}
為什么打印不出來header 'Content-Type' => 'application/json'以及body的值啊?是不是我用錯(cuò)了?
看你是使用的哪個(gè)Container
照著手冊(cè)安裝的 composer require psr/container ^1.1.1 php-di/php-di ^6 doctrine/annotations ^1.14
use support\Container;
配置按照手冊(cè)配置好了
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions(config('dependence', []));
$builder->useAutowiring(true);
$builder->useAnnotations(true);
return $builder->build();
然后根據(jù)手冊(cè)使用// Container創(chuàng)建的實(shí)例可以依賴注入
$user_service = Container::get(UserService::class);
// Container創(chuàng)建的實(shí)例可以依賴注入
$log_service = Container::make(LogService::class, [$path, $name]);