Skip to content

Commit 86af3ac

Browse files
committed
Simplify examples by updating to new default loop
1 parent 602149d commit 86af3ac

File tree

6 files changed

+21
-30
lines changed

6 files changed

+21
-30
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ Once [installed](#install), you can use the following code to query an example
6767
web service via SOAP:
6868

6969
```php
70-
$loop = React\EventLoop\Factory::create();
71-
$browser = new React\Http\Browser($loop);
70+
<?php
71+
72+
require __DIR__ . '/vendor/autoload.php';
73+
74+
$browser = new React\Http\Browser();
7275
$wsdl = 'http://example.com/demo.wsdl';
7376

7477
$browser->get($wsdl)->then(function (Psr\Http\Message\ResponseInterface $response) use ($browser) {
@@ -79,8 +82,6 @@ $browser->get($wsdl)->then(function (Psr\Http\Message\ResponseInterface $respons
7982
var_dump('Result', $result);
8083
});
8184
});
82-
83-
$loop->run();
8485
```
8586

8687
See also the [examples](examples).
@@ -90,16 +91,16 @@ See also the [examples](examples).
9091
### Client
9192

9293
The `Client` class is responsible for communication with the remote SOAP
93-
WebService server.
94+
WebService server. It requires the WSDL file contents and an optional
95+
array of SOAP options:
9496

9597
It requires a [`Browser`](https://github.com/reactphp/http#browser) object
9698
bound to the main [`EventLoop`](https://github.com/reactphp/event-loop#usage)
9799
in order to handle async requests, the WSDL file contents and an optional
98100
array of SOAP options:
99101

100102
```php
101-
$loop = React\EventLoop\Factory::create();
102-
$browser = new React\Http\Browser($loop);
103+
$browser = new React\Http\Browser();
103104

104105
$wsdl = '<?xml ';
105106
$options = array();
@@ -113,7 +114,7 @@ proxy servers etc.), you can explicitly pass a custom instance of the
113114
to the [`Browser`](https://github.com/reactphp/http#browser) instance:
114115
115116
```php
116-
$connector = new React\Socket\Connector($loop, array(
117+
$connector = new React\Socket\Connector(null, array(
117118
'dns' => '127.0.0.1',
118119
'tcp' => array(
119120
'bindto' => '192.168.10.1:0'
@@ -124,7 +125,7 @@ $connector = new React\Socket\Connector($loop, array(
124125
)
125126
));
126127
127-
$browser = new React\Http\Browser($loop, $connector);
128+
$browser = new React\Http\Browser(null, $connector);
128129
$client = new Clue\React\Soap\Client($browser, $wsdl);
129130
```
130131
@@ -134,7 +135,7 @@ you to use local WSDL files, WSDL files from a cache or the most common form,
134135
downloading the WSDL file contents from an URL through the `Browser`:
135136

136137
```php
137-
$browser = new React\Http\Browser($loop);
138+
$browser = new React\Http\Browser();
138139

139140
$browser->get($url)->then(
140141
function (Psr\Http\Message\ResponseInterface $response) use ($browser) {
@@ -366,7 +367,7 @@ clean up any underlying resources.
366367
```php
367368
$promise = $proxy->demo();
368369

369-
$loop->addTimer(2.0, function () use ($promise) {
370+
Loop::addTimer(2.0, function () use ($promise) {
370371
$promise->cancel();
371372
});
372373
```
@@ -389,7 +390,7 @@ pass the timeout to the [underlying `Browser`](https://github.com/reactphp/http#
389390
like this:
390391
391392
```php
392-
$browser = new React\Http\Browser($loop);
393+
$browser = new React\Http\Browser();
393394
$browser = $browser->withTimeout(10.0);
394395
395396
$client = new Clue\React\Soap\Client($browser, $wsdl);

examples/01-client-blz-wsdl.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
require __DIR__ . '/../vendor/autoload.php';
44

5-
$loop = React\EventLoop\Factory::create();
6-
$browser = new React\Http\Browser($loop);
5+
$browser = new React\Http\Browser();
76

87
$blz = isset($argv[1]) ? $argv[1] : '12070000';
98

@@ -21,5 +20,3 @@ function (Exception $e) {
2120
}
2221
);
2322
});
24-
25-
$loop->run();

examples/02-client-blz-non-wsdl.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
require __DIR__ . '/../vendor/autoload.php';
44

5-
$loop = React\EventLoop\Factory::create();
6-
$browser = new React\Http\Browser($loop);
5+
$browser = new React\Http\Browser();
76

87
$blz = isset($argv[1]) ? $argv[1] : '12070000';
98

@@ -23,5 +22,3 @@ function (Exception $e) {
2322
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
2423
}
2524
);
26-
27-
$loop->run();

examples/11-wsdl-info.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
require __DIR__ . '/../vendor/autoload.php';
44

5-
$loop = React\EventLoop\Factory::create();
6-
$browser = new React\Http\Browser($loop);
5+
$browser = new React\Http\Browser();
76

87
$wsdl = isset($argv[1]) ? $argv[1] : 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl';
98

@@ -21,5 +20,3 @@ function (Exception $e) {
2120
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2221
}
2322
);
24-
25-
$loop->run();

src/Client.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
* array of SOAP options:
2020
*
2121
* ```php
22-
* $loop = React\EventLoop\Factory::create();
23-
* $browser = new React\Http\Browser($loop);
22+
* $browser = new React\Http\Browser();
2423
*
2524
* $wsdl = '<?xml …';
2625
* $options = array();
@@ -34,7 +33,7 @@
3433
* to the [`Browser`](https://github.com/clue/reactphp/http#browser) instance:
3534
*
3635
* ```php
37-
* $connector = new React\Socket\Connector($loop, array(
36+
* $connector = new React\Socket\Connector(null, array(
3837
* 'dns' => '127.0.0.1',
3938
* 'tcp' => array(
4039
* 'bindto' => '192.168.10.1:0'
@@ -45,7 +44,7 @@
4544
* )
4645
* ));
4746
*
48-
* $browser = new React\Http\Browser($loop, $connector);
47+
* $browser = new React\Http\Browser(null, $connector);
4948
* $client = new Clue\React\Soap\Client($browser, $wsdl);
5049
* ```
5150
*
@@ -55,7 +54,7 @@
5554
* downloading the WSDL file contents from an URL through the `Browser`:
5655
*
5756
* ```php
58-
* $browser = new React\Http\Browser($loop);
57+
* $browser = new React\Http\Browser();
5958
*
6059
* $browser->get($url)->then(
6160
* function (Psr\Http\Message\ResponseInterface $response) use ($browser) {

tests/FunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function setUpFileBeforeClass()
4242
*/
4343
public function setUpClient()
4444
{
45-
$this->loop = \React\EventLoop\Factory::create();
45+
$this->loop = \React\EventLoop\Loop::get();
4646
$this->client = new Client(new Browser($this->loop), self::$wsdl);
4747
}
4848

0 commit comments

Comments
 (0)