我正在尝试创建一个可以注入到任何地方的服务。为此,我尝试将 Symfony 4.3 的 HttpClient 组件作为参数传递
我向您展示服务
https://i.stack.imgur.com/2384M.png
<?php
namespace App\Service\Callback;
use Symfony\Component\HttpClient\HttpClient;
class Back
{
private $client;
public function __construct(HttpClient $httpClient)
{
$this->client = $httpClient::create();
}
public function sendCallback ( $method, $urlCallback, $option)
{
$response = $this->client->request($method,$urlCallback,$option);
$statusCode = $response->getStatusCode();
return $statusCode;
}
}
Run Code Online (Sandbox Code Playgroud)
好吧,我正在尝试将其加载到 services.yml 中
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each …Run Code Online (Sandbox Code Playgroud)