Skip to content

Commit 4c78061

Browse files
committed
Merge pull request #9 from clue/fields
Rename "part" to "field" in order to match Asterisk terminology
2 parents 842637b + cbd6002 commit 4c78061

10 files changed

Lines changed: 30 additions & 30 deletions

File tree

example/commands.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$api->events(false);
2020

2121
$api->listCommands()->then(function (Response $response) {
22-
echo 'Commands: ' . implode(', ', array_keys($response->getParts())) . PHP_EOL;
22+
echo 'Commands: ' . implode(', ', array_keys($response->getFields())) . PHP_EOL;
2323
});
2424

2525
$client->on('close', function() use ($loop) {
@@ -34,7 +34,7 @@
3434

3535
$api->command($line)->then(
3636
function (Response $response) {
37-
echo $response->getPart('_') . PHP_EOL;
37+
echo $response->getField('_') . PHP_EOL;
3838
},
3939
function (Exception $error) use ($line) {
4040
echo 'Error executing "' . $line . '": ' . $error->getMessage() . PHP_EOL;

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function handleMessage(Message $message)
7979
return;
8080
}
8181

82-
if ($message->getPart('Response') === 'Error') {
82+
if ($message->getField('Response') === 'Error') {
8383
$this->pending[$id]->reject(new ErrorException($message));
8484
} else {
8585
$this->pending[$id]->resolve($message);

src/Protocol/Action.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
class Action extends Message
66
{
7-
public function __construct(array $parts = array())
7+
public function __construct(array $fields = array())
88
{
9-
$this->parts = $parts;
9+
$this->fields = $fields;
1010
}
1111

1212
public function getMessageSerialized()
1313
{
1414
$message = '';
15-
foreach ($this->parts as $key => $values) {
15+
foreach ($this->fields as $key => $values) {
1616
if (!is_array($values)) {
1717
$values = array($values);
1818
}

src/Protocol/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Collection extends Message
1212

1313
public function __construct(Response $response, array $entryEvents, Event $completeEvent)
1414
{
15-
$this->parts = $response->getParts();
15+
$this->fields = $response->getFields();
1616
$this->response = $response;
1717
$this->entryEvents = $entryEvents;
1818
$this->completeEvent = $completeEvent;

src/Protocol/ErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ErrorException extends RuntimeException
1010

1111
public function __construct(Response $response)
1212
{
13-
parent::__construct('Error "' . $response->getPart('Message') . '"');
13+
parent::__construct('Error "' . $response->getField('Message') . '"');
1414
$this->response = $response;
1515
}
1616

src/Protocol/Event.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class Event extends Message
66
{
7-
public function __construct(array $parts)
7+
public function __construct(array $fields)
88
{
9-
$this->parts = $parts;
9+
$this->fields = $fields;
1010
}
1111

1212
public function getName()
1313
{
14-
return $this->getPart('Event');
14+
return $this->getField('Event');
1515
}
1616
}

src/Protocol/Message.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
abstract class Message
66
{
7-
protected $parts = array();
7+
protected $fields = array();
88

99
public function getActionId()
1010
{
11-
return $this->getPart('ActionId');
11+
return $this->getField('ActionId');
1212
}
1313

14-
public function getPart($key)
14+
public function getField($key)
1515
{
1616
$key = strtolower($key);
1717

18-
foreach ($this->parts as $part => $value) {
18+
foreach ($this->fields as $part => $value) {
1919
if (strtolower($part) === $key) {
2020
return $value;
2121
}
@@ -26,11 +26,11 @@ public function getPart($key)
2626

2727
public function toJson()
2828
{
29-
return json_encode($this->getParts());
29+
return json_encode($this->getFields());
3030
}
3131

32-
public function getParts()
32+
public function getFields()
3333
{
34-
return $this->parts;
34+
return $this->fields;
3535
}
3636
}

src/Protocol/Parser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function push($chunk)
4040

4141
private function parseMessage($message)
4242
{
43-
$parts = array();
43+
$fields = array();
4444
foreach (explode(self::EOL, $message) as $line) {
4545
if (substr($line, -self::LCOMMAND_END) === self::COMMAND_END) {
4646
$key = '_';
@@ -54,16 +54,16 @@ private function parseMessage($message)
5454
$key = substr($line, 0, $pos);
5555
}
5656

57-
$parts[$key] = $value;
57+
$fields[$key] = $value;
5858
}
5959

60-
reset($parts);
61-
$key = key($parts);
60+
reset($fields);
61+
$key = key($fields);
6262

6363
if ($key === 'Event') {
64-
return new Event($parts);
64+
return new Event($fields);
6565
}
6666

67-
return new Response($parts);
67+
return new Response($fields);
6868
}
6969
}

src/Protocol/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class Response extends Message
66
{
7-
public function __construct(array $parts)
7+
public function __construct(array $fields)
88
{
9-
$this->parts = $parts;
9+
$this->fields = $fields;
1010
}
1111
}

tests/Protocol/ParserTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testParseResponse()
1616
/* @var $first Clue\React\Ami\Protocol\Response */
1717

1818
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
19-
$this->assertEquals('Success', $first->getPart('Response'));
19+
$this->assertEquals('Success', $first->getField('Response'));
2020
}
2121

2222
public function testParseResponseSpace()
@@ -31,7 +31,7 @@ public function testParseResponseSpace()
3131
/* @var $first Clue\React\Ami\Protocol\Response */
3232

3333
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
34-
$this->assertEquals(' spaces ', $first->getPart('Message'));
34+
$this->assertEquals(' spaces ', $first->getField('Message'));
3535
}
3636

3737
public function testParsingMultipleEvents()
@@ -61,8 +61,8 @@ public function testParsingCommandResponse()
6161
/* @var $first Clue\React\Ami\Protocol\Response */
6262

6363
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
64-
$this->assertEquals('Follows', $first->getPart('Response'));
65-
$this->assertEquals("Testing: yes\nAnother Line\n--END COMMAND--", $first->getPart('_'));
64+
$this->assertEquals('Follows', $first->getField('Response'));
65+
$this->assertEquals("Testing: yes\nAnother Line\n--END COMMAND--", $first->getField('_'));
6666
}
6767

6868
/**

0 commit comments

Comments
 (0)