gpt4 book ai didi

php - 交响服务

转载 作者:可可西里 更新时间:2023-11-01 01:15:54 25 4
gpt4 key购买 nike

请帮助我了解如何在我的服务中注入(inject) buzz http 包以从我的服务发送请求。

我的服务.yml

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;
}
}

但这导致了错误:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Argument 4 passed to AppBundle\Utils\SendMessage::__construct() must be an instance of Buzz\Browser, none given, called in /app/var/cache/prod/appProdProjectContainer.php on line 270" at /app/src/AppBundle/Utils/SendMessage.php line 21 {"exception":"[object]

最佳答案

服务配置文件中定义的每个参数都必须用双引号括起来并用逗号分隔,如上例:

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_bundle.webUrl%, %app_bundle.Url%, %app_bundle.token%, @buzz"

关于php - 交响服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38861967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com