-
Notifications
You must be signed in to change notification settings - Fork 49
Cannot autowire service Http\HttplugBundle\Collector\Formatter #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It seems this class is loaded only with profiling enable: HttplugBundle/DependencyInjection/HttplugExtension.php Lines 58 to 59 in 3da46d5
It seems legit, but it's the only way I found to get httplug logging with this client: https://github.com/docker-php/docker-php/blob/b1f822980dbbaad6c76fbcf1f17d26dfab7c7df6/src/DockerClient.php#L62-L94 Without having to re-define anything. Related to: docker-php/docker-php#257 Maybe it would be great to have a |
I finally solved my issue by creating this class: use Http\HttplugBundle\ClientFactory\ClientFactory;
/**
* Special factory that call another factory not implementing ClientFactory.
*
* @author Sullivan Senechal <[email protected]>
*/
final class CallableClientFactory implements ClientFactory
{
/**
* @var callable
*/
private $factory;
/**
* @param callable $factory
*/
public function __construct(callable $factory)
{
$this->factory = $factory;
}
/**
* {@inheritdoc}
*/
public function createClient(array $config = [])
{
return \call_user_func($this->factory, $config);
}
} And replacing the services:
httplug.factory.docker:
class: AppBundle\Httplug\ClientFactory\CallableClientFactory
arguments:
$factory: [ Docker\DockerClient, 'createFromEnv' ]
Docker\Docker:
arguments:
$httpClient: '@httplug.client.docker' If you think this is a good solution, I may write a PR for that. |
All collector stuff is internal and should not be used by other libraries/bundles. |
what exactly are you trying to achieve @soullivaneuh ? if its about logging, the idea would be to use the logger plugin with the plugin client: http://docs.php-http.org/en/latest/plugins/logger.html if that plugin does not work for you, we need to better understand what you want to do to figure out what the right solution is. |
@dbu It's about logging. My solution currently works, but it's maybe not the simplier. I also forget my configuration file: httplug:
plugins:
logger: ~
clients:
default:
factory: 'httplug.factory.guzzle6'
plugins: ['httplug.plugin.logger']
docker:
factory: 'httplug.factory.docker'
plugins: ['httplug.plugin.logger']
profiling:
captured_body_length: 1000 I have to do this because I have to use this part: https://github.com/docker-php/docker-php/blob/961e1d4f2b5d6617920babe440f585d1d517a763/src/DockerClient.php#L62-L95 Do you have a cleaner view of what I'm trying to do? Can it be done simpler? Maybe a fix must be done on the |
i think i would try to provide a factory. we provide an example in http://docs.php-http.org/en/latest/plugins/introduction.html#plugin-client-libraries - then you can have a DockerFactory::createFromEnv that does most of what the constructor does and don't need your own client class. |
@soullivaneuh did you find a solution, can we close this issue? or do we need to refactor something? |
@dbu I didn't get time to found a solution, but I think it should be solved on docker-php side: docker-php/docker-php#255 (comment) You may close it if you want. I'll open a new one if something more precise has to be done. |
alright. sure, open a new issue or ask us on slack if you need something. |
Actual Behavior
I have the following error with no-debug env:
Expected Behavior
No error and service building like it works with debug setting.
Steps to Reproduce
Define the following services:
And run:
Possible Solutions
See #210 (comment)
The text was updated successfully, but these errors were encountered: