Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony服务_Php_Symfony_Service_Dependency Injection - Fatal编程技术网

Php Symfony服务

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

请帮助我了解如何在我的服务中注入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\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“

非常感谢!我想我需要睡觉,这是个愚蠢的错误。