Я работаю над проектом Symfony 4.2 и использую клиент Guzzle (6.3).
Я создал client.yml и настроил свои клиенты-жадные с помощью base_uri.
clients.yml
parameters:
client_config:
base_uri: ~
defaults:
timeout: '%client_timeout%'
connect_timeout: '%client_connect_timeout%'
verify: false
provider_client_config:
base_uri: '%provider_url%'
defaults:
timeout: '%client_timeout%'
verify: false
connect_timeout: '%client_connect_timeout%'
headers:
content-type: '%client_content_type%'
services:
# Default HTTP Client service
client:
class: GuzzleHttp\Client
arguments: ['%client_config%']
provider_client:
class: GuzzleHttp\Client
arguments: ['%provider_client_config%']
И импортировал мой clients.yml в services.yml.
services.yml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
imports:
- { resource: clients.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
provider_url: 'endpoint'
client_content_type: application/json
client_timeout: 30
client_connect_timeout: 5
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
GuzzleHttp\Client:
public: true
autowire: true
autoconfigure: false
App\Service\Adapter\Provider:
class: App\Service\Adapter\Provider
arguments:
- '@provider_client'
public: true
autowire: true
autoconfigure: false
Когда я пытаюсь отправить запрос от команды с помощью адаптера, клиент Guzzle возвращает ошибку cURL 3: неправильно сформировано.
Команда:
class TestCommand extends Command
{
protected static $defaultName = 'command:command';
/**
* @var Client
*/
private $client;
public function __construct(Client $client)
{
$this->client = $client;
parent::__construct();
}
protected function configure()
{
$this
->setDescription('test.')
->setHelp('test.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$lol = new ProviderOne($this->client);
}
}
Адаптер:
$response = $this->client->request('GET', '');
Где не так в моей конфигурации, я не могу понять это.