-
Notifications
You must be signed in to change notification settings - Fork 50
Add a discovery strategy #85
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Http\HttplugBundle; | ||
|
||
use Http\Client\HttpClient; | ||
use Http\Discovery\Exception\StrategyUnavailableException; | ||
use Http\Discovery\HttpClientDiscovery; | ||
use Http\Discovery\Strategy\DiscoveryStrategy; | ||
|
||
/** | ||
* A strategy that provide clients configured with HTTPlug bundle. | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class ConfiguredClientsStrategy implements DiscoveryStrategy | ||
{ | ||
/** | ||
* @var HttpClient | ||
*/ | ||
private static $client; | ||
|
||
/** | ||
* @param HttpClient $httpClient | ||
*/ | ||
public function __construct(HttpClient $httpClient) | ||
{ | ||
static::$client = $httpClient; | ||
|
||
HttpClientDiscovery::prependStrategy(self::class); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getCandidates($type) | ||
{ | ||
if (static::$client !== null && $type == 'Http\Client\HttpClient') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use HttpClient::class or do we need to support too old php versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, We don't do it in CommonClassesStrategy. But I don't know why i didn't use the ::class constant there. I should probably update here anyhow. Thank you. |
||
return [['class' => function() { return static::$client; }]]; | ||
} | ||
|
||
return []; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we put this in a sub-namespace "Discovery"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.