Skip to content

Commit 63f042d

Browse files
committed
Collection now extends Response
1 parent 5f9957c commit 63f042d

2 files changed

Lines changed: 74 additions & 19 deletions

File tree

README.md

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ monitor the status of subscribers, channels or queues.
4747
* [getActionId()](#getactionid)
4848
* [Response](#response)
4949
* [getCommandOutput()](#getcommandoutput)
50+
* [Collection](#collection)
51+
* [getEntryEvents()](#getentryevents)
52+
* [getCompleteEvent()](#getcompleteevent)
5053
* [Action](#action)
5154
* [Event](#event)
5255
* [getName()](#getname)
@@ -205,9 +208,8 @@ $sender = new ActionSender($client);
205208
All public methods resemble their respective AMI actions.
206209

207210
```php
208-
$sender->ping()->then(function (Response $response) {
209-
// response received for ping action
210-
});
211+
$sender->ping();
212+
// many more…
211213
```
212214

213215
Listing all available actions is out of scope here, please refer to the [class outline](src/ActionSender.php).
@@ -247,7 +249,8 @@ A PR that updates the `ActionSender` is very much appreciated :)
247249

248250
### Message
249251

250-
The `Message` is an abstract base class for the [`Response`](#response), [`Action`](#action) and [`Event`](#event) value objects.
252+
The `Message` is an abstract base class for the [`Response`](#response),
253+
[`Action`](#action) and [`Event`](#event) value objects.
251254
It provides a common interface for these three message types.
252255

253256
Each `Message` consists of any number of fields with each having a name and one or multiple values.
@@ -272,12 +275,12 @@ The `getFields(): array` method can be used to get an array of all fields.
272275
The `getActionId(): string` method can be used to get the unique action ID of this message.
273276
This is a shortcut to get the value of the "ActionID" field.
274277

275-
#### Response
278+
### Response
276279

277280
The `Response` value object represents the incoming response received from the AMI.
278281
It shares all properties of the [`Message`](#message) parent class.
279282

280-
##### getCommandOutput()
283+
#### getCommandOutput()
281284

282285
The `getCommandOutput(): ?string` method can be used to get the resulting output of
283286
a "command" [`Action`](#action).
@@ -290,17 +293,78 @@ $sender->command('help')->then(function (Response $response) {
290293
});
291294
```
292295

293-
#### Action
296+
### Collection
297+
298+
The `Collection` value object represents an incoming response received from the AMI
299+
for certain actions that return a list of entries.
300+
It shares all properties of the [`Response`](#response) parent class.
301+
302+
You can access the `Collection` like a normal `Response` in order to access
303+
the leading `Response` for this collection or you can use the below methods
304+
to access the list entries and completion event.
305+
306+
```
307+
Action: CoreShowChannels
308+
Response: Success
309+
EventList: start
310+
Message: Channels will follow
311+
312+
Event: CoreShowChannel
313+
Channel: SIP / 123
314+
ChannelState: 6
315+
ChannelStateDesc: Up
316+
317+
318+
Event: CoreShowChannel
319+
Channel: SIP / 456
320+
ChannelState: 6
321+
ChannelStateDesc: Up
322+
323+
324+
Event: CoreShowChannel
325+
Channel: SIP / 789
326+
ChannelState: 6
327+
ChannelStateDesc: Up
328+
329+
330+
Event: CoreShowChannelsComplete
331+
EventList: Complete
332+
ListItems: 3
333+
```
334+
335+
#### getEntryEvents()
336+
337+
The `getEntryEvents(): Event[]` method can be used to get the list of all
338+
intermediary `Event` objects where each entry represents a single entry in the
339+
collection.
340+
341+
```php
342+
foreach ($collection->getEntryEvents() as $entry) {
343+
/* @var $entry Event */
344+
echo $entry->getFieldValue('Channel') . PHP_EOL;
345+
}
346+
```
347+
348+
#### getCompleteEvent()
349+
350+
The `getCompleteEvent(): Event` method can be used to get the trailing
351+
`Event` that completes this collection.
352+
353+
```php
354+
echo $collection->getCompleteEvent()->getFieldValue('ListItems') . PHP_EOL;
355+
```
356+
357+
### Action
294358

295359
The `Action` value object represents an outgoing action message to be sent to the AMI.
296360
It shares all properties of the [`Message`](#message) parent class.
297361

298-
#### Event
362+
### Event
299363

300364
The `Event` value object represents the incoming event received from the AMI.
301365
It shares all properties of the [`Message`](#message) parent class.
302366

303-
##### getName()
367+
#### getName()
304368

305369
The `getName(): ?string` method can be used to get the name of the event.
306370
This is a shortcut to get the value of the "Event" field.

src/Protocol/Collection.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,18 @@
22

33
namespace Clue\React\Ami\Protocol;
44

5-
use UnexpectedValueException;
6-
7-
class Collection extends Message
5+
class Collection extends Response
86
{
9-
private $response;
107
private $entryEvents;
118
private $completeEvent;
129

1310
public function __construct(Response $response, array $entryEvents, Event $completeEvent)
1411
{
1512
$this->fields = $response->getFields();
16-
$this->response = $response;
1713
$this->entryEvents = $entryEvents;
1814
$this->completeEvent = $completeEvent;
1915
}
2016

21-
public function getResponse()
22-
{
23-
return $this->response;
24-
}
25-
2617
public function getEntryEvents()
2718
{
2819
return $this->entryEvents;

0 commit comments

Comments
 (0)