Skip to content

Commit 21b22f5

Browse files
committed
Use full namespaces in examples and improve them
1 parent 95e5e7d commit 21b22f5

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

examples/commands.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
<?php
22

3-
use Clue\React\Ami\Factory;
4-
use Clue\React\Ami\Client;
5-
use Clue\React\Ami\ActionSender;
6-
use Clue\React\Ami\Protocol\Response;
73
use React\EventLoop\Loop;
84

95
require __DIR__ . '/../vendor/autoload.php';
106

11-
$factory = new Factory();
7+
$factory = new Clue\React\Ami\Factory();
128

139
$target = isset($argv[1]) ? $argv[1] : 'name:password@localhost';
1410

15-
$factory->createClient($target)->then(function (Client $client) {
11+
$factory->createClient($target)->then(function (Clue\React\Ami\Client $client) {
1612
echo 'Client connected. Use STDIN to send CLI commands via asterisk AMI.' . PHP_EOL;
17-
$sender = new ActionSender($client);
13+
$sender = new Clue\React\Ami\ActionSender($client);
1814

1915
$sender->events(false);
2016

21-
$sender->listCommands()->then(function (Response $response) {
17+
$sender->listCommands()->then(function (Clue\React\Ami\Protocol\Response $response) {
2218
echo 'Commands: ' . implode(', ', array_keys($response->getFields())) . PHP_EOL;
2319
});
2420

@@ -33,12 +29,14 @@
3329
echo '<' . $line . PHP_EOL;
3430

3531
$sender->command($line)->then(
36-
function (Response $response) {
32+
function (Clue\React\Ami\Protocol\Response $response) {
3733
echo $response->getCommandOutput() . PHP_EOL;
3834
},
3935
function (Exception $error) use ($line) {
4036
echo 'Error executing "' . $line . '": ' . $error->getMessage() . PHP_EOL;
4137
}
4238
);
4339
});
44-
}, 'var_dump');
40+
}, function (Exception $error) {
41+
echo 'Connection error: ' . $error;
42+
});

examples/events.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
<?php
22

3-
use Clue\React\Ami\Factory;
4-
use Clue\React\Ami\Client;
5-
use Clue\React\Ami\ActionSender;
6-
use Clue\React\Ami\Protocol\Response;
7-
use Clue\React\Ami\Protocol\Event;
8-
93
require __DIR__ . '/../vendor/autoload.php';
104

11-
$factory = new Factory();
5+
$factory = new Clue\React\Ami\Factory();
126

137
$target = isset($argv[1]) ? $argv[1] : 'name:password@localhost';
148

159
$factory->createClient($target)->then(
16-
function (Client $client) {
10+
function (Clue\React\Ami\Client $client) {
1711
echo 'Client connected ' . PHP_EOL;
1812

19-
$sender = new ActionSender($client);
13+
$sender = new Clue\React\Ami\ActionSender($client);
2014
$sender->events(true);
2115

2216
$client->on('close', function() {
2317
echo 'Connection closed' . PHP_EOL;
2418
});
2519

26-
$client->on('event', function (Event $event) {
20+
$client->on('event', function (Clue\React\Ami\Protocol\Event $event) {
2721
echo 'Event: ' . $event->getName() . ': ' . json_encode($event->getFields()) . PHP_EOL;
2822
});
2923
},

examples/peers.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
<?php
22

3-
use Clue\React\Ami\ActionSender;
4-
use Clue\React\Ami\Client;
5-
use Clue\React\Ami\Factory;
6-
use Clue\React\Ami\Protocol\Collection;
7-
83
require __DIR__ . '/../vendor/autoload.php';
94

10-
$factory = new Factory();
5+
$factory = new Clue\React\Ami\Factory();
116

127
$target = isset($argv[1]) ? $argv[1] : 'name:password@localhost';
138

14-
$factory->createClient($target)->then(function (Client $client) {
9+
$factory->createClient($target)->then(function (Clue\React\Ami\Client $client) {
1510
echo 'Successfully connected' . PHP_EOL;
1611

17-
$collector = new ActionSender($client);
12+
$collector = new Clue\React\Ami\ActionSender($client);
1813

19-
$collector->sipPeers()->then(function (Collection $collection) {
14+
$collector->sipPeers()->then(function (Clue\React\Ami\Protocol\Collection $collection) {
2015
var_dump('result', $collection);
2116
$peers = $collection->getEntryEvents();
2217

2318
echo 'found ' . count($peers) . ' peers' . PHP_EOL;
2419
});
25-
}, 'var_dump');
20+
}, function (Exception $error) {
21+
echo 'Connection error: ' . $error;
22+
});

0 commit comments

Comments
 (0)