Closed sagikazarmark closed 9 years ago
Agreed. One can configure the client before wrapping it in the adapter.
:+1:
I'm little late, but IMO, following discussion in #62, not having a way to have different behavior for treating requests over the same client is a blocker.
@dbu suggets having different clients, the code in #62 was only a example, in this library https://github.com/stage1/docker-php i have 3 to 4 differents behavior on how the client must react for a request, which can be mixed, so with the current implementation i may need to have 10 to 16 differents http client which his just stupid.
It may be not with a $options argument (this can be done with plugins ?) but for my library (and if i have this case, i must not be alone) i need to handle different behavior per request.
So it is something that httplug should handle ? Or should i not use this library ?
maybe a plugin can help. or something that can use meta information on a request?
what kind of behavior do you need to control? i kind of hope that the concrete examples inspire ideas how we can best solve this...
In fact i need to control the timeout / async - sync / and also a way to have a callback when reading the stream, i agree as all those things can be handle in a plugin or in constructor options, but i don't want to handle a huge number of clients for those behaviour as some time i need to set a specific timeout and a async request, sometimes it's just the timeout, sometimes just the async, ....
Another way as the $options paramter is maybe provide a good way to facilite the creation of the PluginClient via a Factory (So i can have different layer given a call) ?
Maybe something like this :
interface PluginFactory
{
public static function getName();
/**
* @return Plugin
*/
public static function create(array $options = []);
}
class PluginClientFactory
{
private $plugins;
public function addPluginFactory($pluginFactory)
{
$this->plugins[$pluginFactory::getName()] = $pluginFactory;
}
public function create($create, HttpPsrClient $client)
{
$pluginClient = new PluginClient($client);
foreach ($create as $name => $options) {
$pluginClient->addPlugin($this->[$name]::create($options));
}
return $pluginClient;
}
}
PS : Don't mind incorrect syntax, just a POC :)
So having this factory we can easily have different behavior per request when we need ?
In a previous PR we started to think with @dbu that we should drop the options argument. So far we could only found the
timeout
option which could be passed there. We would like to prevent that options is used for client specific things.Actually timeout is something that might not be needed to be set for every request, but configured in the constructor.
So the current proposal is to drop the options parameter entirely.