diff --git a/README.md b/README.md index 1f2a641..ca7c975 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ Once [installed](#install), you can use the following code to access your local Asterisk instance and issue some simple commands via AMI: ```php +createClient('user:secret@localhost')->then(function (Clue\React\Ami\Client $client) { @@ -118,7 +122,7 @@ proxy servers etc.), you can explicitly pass a custom instance of the [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface): ```php -$connector = new React\Socket\Connector(null, array( +$connector = new React\Socket\Connector(array( 'dns' => '127.0.0.1', 'tcp' => array( 'bindto' => '192.168.10.1:0' @@ -546,7 +550,7 @@ This is a shortcut to get the value of the "Event" field. ## Install -The recommended way to install this library is [through Composer](https://getcomposer.org). +The recommended way to install this library is [through Composer](https://getcomposer.org/). [New to Composer?](https://getcomposer.org/doc/00-intro.md) This project follows [SemVer](https://semver.org/). @@ -560,12 +564,12 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+. -It's *highly recommended to use PHP 7+* for this project. +It's *highly recommended to use the latest supported PHP version* for this project. ## Tests To run the test suite, you first need to clone this repo and then install all -dependencies [through Composer](https://getcomposer.org): +dependencies [through Composer](https://getcomposer.org/): ```bash $ composer install @@ -574,7 +578,7 @@ $ composer install To run the test suite, go to the project root and run: ```bash -$ php vendor/bin/phpunit +$ vendor/bin/phpunit ``` The test suite contains both unit tests and functional integration tests. diff --git a/composer.json b/composer.json index 0ae98a7..6e57965 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "evenement/evenement": "^3.0 || ^2.0 || ^1.0", "react/event-loop": "^1.2", "react/promise": "^2.0 || ^1.1", - "react/socket": "^1.8" + "react/socket": "^1.9" }, "require-dev": { "clue/block-react": "^1.2", diff --git a/examples/commands.php b/examples/commands.php index ec26244..3837290 100644 --- a/examples/commands.php +++ b/examples/commands.php @@ -1,24 +1,20 @@ createClient($target)->then(function (Client $client) { +$factory->createClient($target)->then(function (Clue\React\Ami\Client $client) { echo 'Client connected. Use STDIN to send CLI commands via asterisk AMI.' . PHP_EOL; - $sender = new ActionSender($client); + $sender = new Clue\React\Ami\ActionSender($client); $sender->events(false); - $sender->listCommands()->then(function (Response $response) { + $sender->listCommands()->then(function (Clue\React\Ami\Protocol\Response $response) { echo 'Commands: ' . implode(', ', array_keys($response->getFields())) . PHP_EOL; }); @@ -33,7 +29,7 @@ echo '<' . $line . PHP_EOL; $sender->command($line)->then( - function (Response $response) { + function (Clue\React\Ami\Protocol\Response $response) { echo $response->getCommandOutput() . PHP_EOL; }, function (Exception $error) use ($line) { @@ -41,4 +37,6 @@ function (Exception $error) use ($line) { } ); }); -}, 'var_dump'); +}, function (Exception $error) { + echo 'Connection error: ' . $error; +}); diff --git a/examples/events.php b/examples/events.php index 5373235..ce91d4b 100644 --- a/examples/events.php +++ b/examples/events.php @@ -1,29 +1,23 @@ createClient($target)->then( - function (Client $client) { + function (Clue\React\Ami\Client $client) { echo 'Client connected ' . PHP_EOL; - $sender = new ActionSender($client); + $sender = new Clue\React\Ami\ActionSender($client); $sender->events(true); $client->on('close', function() { echo 'Connection closed' . PHP_EOL; }); - $client->on('event', function (Event $event) { + $client->on('event', function (Clue\React\Ami\Protocol\Event $event) { echo 'Event: ' . $event->getName() . ': ' . json_encode($event->getFields()) . PHP_EOL; }); }, diff --git a/examples/peers.php b/examples/peers.php index 9dbd012..edf168f 100644 --- a/examples/peers.php +++ b/examples/peers.php @@ -1,25 +1,22 @@ createClient($target)->then(function (Client $client) { +$factory->createClient($target)->then(function (Clue\React\Ami\Client $client) { echo 'Successfully connected' . PHP_EOL; - $collector = new ActionSender($client); + $collector = new Clue\React\Ami\ActionSender($client); - $collector->sipPeers()->then(function (Collection $collection) { + $collector->sipPeers()->then(function (Clue\React\Ami\Protocol\Collection $collection) { var_dump('result', $collection); $peers = $collection->getEntryEvents(); echo 'found ' . count($peers) . ' peers' . PHP_EOL; }); -}, 'var_dump'); +}, function (Exception $error) { + echo 'Connection error: ' . $error; +}); diff --git a/src/Factory.php b/src/Factory.php index d560b7d..5345283 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -25,7 +25,7 @@ * [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface): * * ```php - * $connector = new React\Socket\Connector(null, array( + * $connector = new React\Socket\Connector(array( * 'dns' => '127.0.0.1', * 'tcp' => array( * 'bindto' => '192.168.10.1:0' @@ -46,7 +46,7 @@ class Factory public function __construct(LoopInterface $loop = null, ConnectorInterface $connector = null) { if ($connector === null) { - $connector = new Connector($loop); + $connector = new Connector(array(), $loop); } $this->connector = $connector;