-
Notifications
You must be signed in to change notification settings - Fork 6
Fix composer version conflict with react/http v0.8 #28
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
Merged
dbu
merged 5 commits into
php-http:master
from
samuelnogueira:update-react-http-client-dependency
Dec 21, 2017
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a91065
Fix composer version conflict with react/http v0.8
f305b04
Added possibility to build Http Client passing a Connector instead of…
4e2ca57
ReactFactory is now compatible with both react/http-client v0.4 and v0.5
07dfeda
Applied StyleCI suggested fixes
4389772
- E_USER_DEPRECATED now triggered when using deprecated behavior in R…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
use React\EventLoop\Factory as EventLoopFactory; | ||
use React\Dns\Resolver\Resolver as DnsResolver; | ||
use React\Dns\Resolver\Factory as DnsResolverFactory; | ||
use React\HttpClient\Factory as HttpClientFactory; | ||
use React\HttpClient\Client as HttpClient; | ||
use React\Socket\Connector; | ||
use React\Socket\ConnectorInterface; | ||
|
||
/** | ||
* Factory wrapper for React instances. | ||
|
@@ -43,24 +44,45 @@ public static function buildDnsResolver( | |
return $factory->createCached($dns, $loop); | ||
} | ||
|
||
/** | ||
* @param LoopInterface $loop | ||
* @param DnsResolver|null $dns | ||
* | ||
* @return ConnectorInterface | ||
*/ | ||
public static function buildConnector( | ||
LoopInterface $loop, | ||
DnsResolver $dns = null | ||
) { | ||
if (null === $dns) { | ||
$dns = self::buildDnsResolver($loop); | ||
} | ||
|
||
return new Connector($loop, ['dns' => $dns]); | ||
} | ||
|
||
/** | ||
* Build a React Http Client. | ||
* | ||
* @param LoopInterface $loop | ||
* @param DnsResolver $dns | ||
* @param LoopInterface $loop | ||
* @param ConnectorInterface|DnsResolver $connector Passing a DnsResolver instance is deprecated. Should pass a | ||
* ConnectorInterface instance. | ||
* | ||
* @return HttpClient | ||
*/ | ||
public static function buildHttpClient( | ||
LoopInterface $loop, | ||
DnsResolver $dns = null | ||
$connector = null | ||
) { | ||
if (null === $dns) { | ||
$dns = self::buildDnsResolver($loop); | ||
// build a connector if none is given, or create one attaching given DnsResolver (old deprecated behavior) | ||
if (null === $connector || $connector instanceof DnsResolver) { | ||
$connector = static::buildConnector($loop, $connector); | ||
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. I think we should only build connector if it's a Resolver, when it's null we should let React do this job as it's an optional argument (less code to maintain as we don't have to follow the default behavior of react of creating a dns connector) |
||
} | ||
|
||
$factory = new HttpClientFactory(); | ||
if (!$connector instanceof ConnectorInterface) { | ||
throw new \InvalidArgumentException('$connector must be an instance of ConnectorInterface or DnsResolver'); | ||
} | ||
|
||
return $factory->create($loop, $dns); | ||
return new HttpClient($loop, $connector); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Http\Adapter\React\Tests; | ||
|
||
use Http\Adapter\React\ReactFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use React\Dns\Resolver\Resolver; | ||
use React\EventLoop\LoopInterface; | ||
use React\HttpClient\Client; | ||
use React\Socket\ConnectorInterface; | ||
|
||
/** | ||
* These tests don't really ensure the correct instances are baked into the returned http client, instead, they are | ||
* just testing the code against the expected use cases. | ||
* | ||
* @author Samuel Nogueira <[email protected]> | ||
*/ | ||
class ReactFactoryTest extends TestCase | ||
{ | ||
/** | ||
* @var \React\EventLoop\LoopInterface | ||
*/ | ||
private $loop; | ||
|
||
protected function setUp() | ||
{ | ||
$this->loop = $this->createMock(LoopInterface::class); | ||
} | ||
|
||
public function testBuildHttpClientWithConnector() | ||
{ | ||
$client = ReactFactory::buildHttpClient($this->loop, $this->createMock(ConnectorInterface::class)); | ||
$this->assertInstanceOf(Client::class, $client); | ||
} | ||
|
||
/** | ||
* @deprecated Building HTTP client passing a DnsResolver instance is deprecated. Should pass a ConnectorInterface | ||
* instance instead. | ||
*/ | ||
public function testBuildHttpClientWithDnsResolver() | ||
{ | ||
$client = ReactFactory::buildHttpClient($this->loop, $this->createMock(Resolver::class)); | ||
$this->assertInstanceOf(Client::class, $client); | ||
} | ||
|
||
public function testBuildHttpClientWithoutConnector() | ||
{ | ||
$client = ReactFactory::buildHttpClient($this->loop); | ||
$this->assertInstanceOf(Client::class, $client); | ||
} | ||
|
||
public function testBuildHttpClientWithInvalidConnectorThrowsException() | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
ReactFactory::buildHttpClient($this->loop, $this->createMock(LoopInterface::class)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we keep allowing 0.4.8 or are there BC breaks?
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.
Unfortunately there are: https://github.com/reactphp/http-client/releases/tag/v0.5.0
Furthermore,
\React\HttpClient\Client
's constructor signature has changed, so even calling it directly instead of usingFactory
won't work the same in v0.4 and v0.5.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.
okay. i suggest we bump the minor version of this library then, and deprecate passing the dns resolver but still support it (see my comment above)
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.
I think we can be BC here and keep 0.4.8 by checking if this
React\HttpClient\Factory
class exists, then use old behavior in that case, otherwise use the new behavior