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