File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -183,6 +183,17 @@ This is a shortcut to get the value of the "ActionID" field.
183183The ` Response ` value object represents the incoming response received from the AMI.
184184It shares all properties of the [ ` Message ` ] ( #message ) parent class.
185185
186+ The ` getCommandOutput() ` method can be used to get the resulting output of
187+ a "command" [ ` Action ` ] ( #action ) .
188+ This value is only available if this is actually a response to a "command" action,
189+ otherwise it defaults to ` null ` .
190+
191+ ``` php
192+ $sender->command('help')->then(function (Response $response) {
193+ echo $response->getCommandOutput();
194+ });
195+ ```
196+
186197#### Action
187198
188199The ` Action ` value object represents an outgoing action message to be sent to the AMI.
Original file line number Diff line number Diff line change 3434
3535 $ api ->command ($ line )->then (
3636 function (Response $ response ) {
37- echo $ response ->getFieldValue ( ' _ ' ) . PHP_EOL ;
37+ echo $ response ->getCommandOutput ( ) . PHP_EOL ;
3838 },
3939 function (Exception $ error ) use ($ line ) {
4040 echo 'Error executing " ' . $ line . '": ' . $ error ->getMessage () . PHP_EOL ;
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ private function parseMessage($message)
4747 foreach ($ lines as $ i => $ line ) {
4848 $ pos = strlen ($ line ) - self ::LCOMMAND_END - 1 ;
4949 if ($ i === $ last && substr ($ line , -self ::LCOMMAND_END ) === self ::COMMAND_END && ($ pos < 0 || $ line [$ pos ] === "\n" )) {
50- $ key = ' _ ' ;
50+ $ key = Response:: FIELD_COMMAND_OUTPUT ;
5151 $ value = $ line ;
5252 } else {
5353 $ pos = strpos ($ line , ': ' );
Original file line number Diff line number Diff line change 44
55class Response extends Message
66{
7+ /** @internal */
8+ const FIELD_COMMAND_OUTPUT = '_ ' ;
9+
710 public function __construct (array $ fields )
811 {
912 $ this ->fields = $ fields ;
1013 }
14+
15+ public function getCommandOutput ()
16+ {
17+ return $ this ->getFieldValue (self ::FIELD_COMMAND_OUTPUT );
18+ }
1119}
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ public function testParsingCommandResponse()
7878
7979 $ this ->assertInstanceOf ('Clue\React\Ami\Protocol\Response ' , $ first );
8080 $ this ->assertEquals ('Follows ' , $ first ->getFieldValue ('Response ' ));
81- $ this ->assertEquals ("Testing: yes \nAnother Line \n--END COMMAND-- " , $ first ->getFieldValue ( ' _ ' ));
81+ $ this ->assertEquals ("Testing: yes \nAnother Line \n--END COMMAND-- " , $ first ->getCommandOutput ( ));
8282 }
8383
8484 public function testParsingCommandResponseEmpty ()
@@ -94,7 +94,7 @@ public function testParsingCommandResponseEmpty()
9494
9595 $ this ->assertInstanceOf ('Clue\React\Ami\Protocol\Response ' , $ first );
9696 $ this ->assertEquals ('Follows ' , $ first ->getFieldValue ('Response ' ));
97- $ this ->assertEquals ("--END COMMAND-- " , $ first ->getFieldValue ( ' _ ' ));
97+ $ this ->assertEquals ("--END COMMAND-- " , $ first ->getCommandOutput ( ));
9898 }
9999
100100 public function testParsingResponseIsNotCommandResponse ()
You can’t perform that action at this time.
0 commit comments