Php Symfony服务
请帮助我了解如何在我的服务中注入buzz http包,以从我的服务发送请求 我的服务Php Symfony服务,php,symfony,service,dependency-injection,Php,Symfony,Service,Dependency Injection,请帮助我了解如何在我的服务中注入buzz http包,以从我的服务发送请求 我的服务 parameters: app_bundle.webUrl: https://url.com/ app_bundle.Url: https://test.com app_bundle.token: rerwe9888rewrjjewrwj services: app_bundle.send_message: class: AppBundle\Utils\Send
parameters:
app_bundle.webUrl: https://url.com/
app_bundle.Url: https://test.com
app_bundle.token: rerwe9888rewrjjewrwj
services:
app_bundle.send_message:
class: AppBundle\Utils\SendMessage
arguments: ["%app_bundle.webUrl%, %app_bundle.Url%, %app_bundle.token%, @buzz"]
我的AppBundle\Utils\SendMessage
<?php
namespace AppBundle\Utils;
class SendMessage
{
/**
* SendMessage constructor.
*
* @param $webUrl
* @param $Url
* @param $token
* @param Browser $buzz
*/
public function __construct($webUrl, $Url, $token, Browser $buzz)
{
$this->webUrl = $webUrl;
$this->Url = $Url;
$this->token = $token;
$this->buzz = $buzz;
}
/**
* @param $action
* @param null $data
* @return mixed
*/
private function sendRequest($action, $data = NULL)
{
$headers = array(
'Content-Type' => 'application/json',
);
$response = $this->buzz->post($this->Url . $this->token . '/' . $action, $headers, json_encode($data));
return $response;
}
}
服务配置文件中定义的每个参数必须用双引号括起来,并用逗号分隔,如上例所示:
parameters:
app_bundle.webUrl: https://url.com/
app_bundle.Url: https://test.com
app_bundle.token: rerwe9888rewrjjewrwj
services:
app_bundle.send_message:
class: AppBundle\Utils\SendMessage
arguments: ["%app_bundle.webUrl%", "%app_bundle.Url%", "%app_bundle.token%", "@buzz"]
您只为构造函数提供了一个字符串参数:%app\u bundle.webUrl%,%app\u bundle.Url%,%app\u bundle.token%,@buzz“
非常感谢!我想我需要睡觉,这是个愚蠢的错误。