@@ -82,8 +82,7 @@ Once [installed](#install), you can use the following code to access your local
82
82
Asterisk instance and issue some simple commands via AMI:
83
83
84
84
``` php
85
- $loop = React\EventLoop\Factory::create();
86
- $factory = new Clue\React\Ami\Factory($loop);
85
+ $factory = new Clue\React\Ami\Factory();
87
86
88
87
$factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\Client $client) {
89
88
echo 'Client connected' . PHP_EOL;
@@ -94,8 +93,6 @@ $factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\C
94
93
var_dump($response);
95
94
});
96
95
});
97
-
98
- $loop->run();
99
96
```
100
97
101
98
See also the [ examples] ( examples ) .
@@ -105,19 +102,23 @@ See also the [examples](examples).
105
102
### Factory
106
103
107
104
The ` Factory ` is responsible for creating your [ ` Client ` ] ( #client ) instance.
108
- It also registers everything with the main [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage ) .
109
105
110
106
``` php
111
- $loop = React\EventLoop\Factory::create();
112
- $factory = new Clue\React\Ami\Factory($loop);
107
+ $factory = new Clue\React\Ami\Factory();
113
108
```
114
109
110
+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
111
+ pass the event loop instance to use for this object. You can use a ` null ` value
112
+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
113
+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
114
+ given event loop instance.
115
+
115
116
If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
116
117
proxy servers etc.), you can explicitly pass a custom instance of the
117
118
[ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
118
119
119
120
``` php
120
- $connector = new React\Socket\Connector($loop , array(
121
+ $connector = new React\Socket\Connector(null , array(
121
122
'dns' => '127.0.0.1',
122
123
'tcp' => array(
123
124
'bindto' => '192.168.10.1:0'
@@ -128,7 +129,7 @@ $connector = new React\Socket\Connector($loop, array(
128
129
)
129
130
));
130
131
131
- $factory = new Clue\React\Ami\Factory($loop , $connector);
132
+ $factory = new Clue\React\Ami\Factory(null , $connector);
132
133
```
133
134
134
135
#### createClient()
@@ -377,11 +378,11 @@ The resulting blocking code could look something like this:
377
378
378
379
``` php
379
380
use Clue\React\Block;
381
+ use React\EventLoop\Loop;
380
382
381
383
function getSipPeers()
382
384
{
383
- $loop = React\EventLoop\Factory::create();
384
- $factory = new Clue\React\Ami\Factory($loop);
385
+ $factory = new Clue\React\Ami\Factory();
385
386
386
387
$target = 'name:password@localhost';
387
388
$promise = $factory->createClient($target)->then(function (Clue\React\Ami\Client $client) {
@@ -393,7 +394,7 @@ function getSipPeers()
393
394
return $ret;
394
395
});
395
396
396
- return Block\await($promise, $loop , 5.0);
397
+ return Block\await($promise, Loop::get() , 5.0);
397
398
}
398
399
```
399
400
0 commit comments