From 12d2fdac3c385aa08a53ce28e59f6c7a365af4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 6 Apr 2015 18:12:07 +0200 Subject: [PATCH 1/2] Add Browser::withSender() method --- src/Browser.php | 8 ++++++++ tests/BrowserTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/BrowserTest.php diff --git a/src/Browser.php b/src/Browser.php index 4913708..0d949a9 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -92,4 +92,12 @@ public function withOptions(array $options) return $browser; } + + public function withSender(Sender $sender) + { + $browser = clone $this; + $browser->sender = $sender; + + return $browser; + } } diff --git a/tests/BrowserTest.php b/tests/BrowserTest.php new file mode 100644 index 0000000..46113f2 --- /dev/null +++ b/tests/BrowserTest.php @@ -0,0 +1,27 @@ +loop = $this->getMock('React\EventLoop\LoopInterface'); + $this->sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock(); + $this->browser = new Browser($this->loop, $this->sender); + } + + public function testWithSender() + { + $sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock(); + + $browser = $this->browser->withSender($sender); + + $this->assertNotSame($this->browser, $browser); + } +} From 468bc2e2786ec450d526b58dde8a1ea5aad35a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 29 Jul 2015 20:44:49 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 5aea7c9..a260ed4 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,32 @@ The `request($method, $url, $headers = array(), $content = '')` method can be us The `send(Request $request)` method can be used to send an arbitrary [`Request` object](#request). +#### withOptions() + +The `withOptions(array $options)` method can be used to change the [options](#options) to use: + +```php +$newBrowser = $browser->withOptions($options); +``` + +Notice that the [`Browser`](#browser) is an immutable object, i.e. the `withOptions()` method +actually returns a *new* [`Browser`](#browser) instance with the [options](#options) applied. + +See [options](#options) for more details. + +#### withSender() + +The `withSender(Sender $sender)` method can be used to change the [`Sender`](#sender) instance to use: + +```php +$newBrowser = $browser->withSender($sender); +``` + +Notice that the [`Browser`](#browser) is an immutable object, i.e. the `withSender()` method +actually returns a *new* [`Browser`](#browser) instance with the given [`Sender`](#sender) applied. + +See [`Sender`](#sender) for more details. + ### Message The `Message` is an abstract base class for the [`Response`](#response) and [`Request`](#request). @@ -139,6 +165,8 @@ and keeps track of its transmission and converts its reponses back to [`Response It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage) and the default [`Connector`](https://github.com/reactphp/socket-client) and [DNS `Resolver`](https://github.com/reactphp/dns). +See also [`Browser::withSender()`](#withsender) for changing the `Sender` instance during runtime. + ### SOCKS proxy You can also establish your outgoing connections through a SOCKS proxy server