Skip to content

Commit

Permalink
Cleaner way to get response values for events.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Smith committed Mar 15, 2016
1 parent 088987b commit 65ed736
Show file tree
Hide file tree
Showing 32 changed files with 92 additions and 141 deletions.
55 changes: 24 additions & 31 deletions src/wormling/phparia/Events/BridgeAttendedTransfer.php
Expand Up @@ -27,7 +27,7 @@
*
* @author Brian Smith <wormling@gmail.com>
*/
class BridgeAttendedTransfer extends Event
class BridgeAttendedTransfer extends BridgeTransfer
{
/**
* @var string (optional) - Application that has been transferred into
Expand Down Expand Up @@ -245,35 +245,28 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->destinationApplication = property_exists($this->response,
'destination_application') ? $this->response->destination_application : null;
$this->destinationBridge = property_exists($this->response,
'destination_bridge') ? $this->response->destination_bridge : null;
$this->destinationLinkFirstLeg = property_exists($this->response,
'destination_link_first_leg') ? new Channel($client, $this->response->destination_link_first_leg) : null;
$this->destinationLinkSecondLeg = property_exists($this->response,
'destination_link_second_leg') ? new Channel($client, $this->response->destination_link_second_leg) : null;
$this->destinationThreewayBridge = property_exists($this->response,
'destination_threeway_bridge') ? new Bridge($client, $this->response->destination_threeway_bridge) : null;
$this->destinationThreewayChannel = property_exists($this->response,
'destination_threeway_channel') ? new Channel($client,
$this->response->destination_threeway_channel) : null;
$this->destinationType = property_exists($this->response,
'destination_type') ? $this->response->destination_type : null;
$this->isExternal = $this->response->is_external;
$this->replaceChannel = property_exists($this->response, 'replace_channel') ? new Channel($client,
$this->response->replace_channel) : null;
$this->result = $this->response->result;
$this->transferTarget = property_exists($this->response, 'transfer_target') ? new Channel($client,
$this->response->transfer_target) : null;
$this->transferee = property_exists($this->response, 'transferee') ? new Channel($client,
$this->response->transferee) : null;
$this->transfererFirstLeg = new Channel($client, $this->response->transferer_first_leg);
$this->transfererFirstLegBridge = property_exists($this->response,
'transferer_first_leg_bridge') ? new Bridge($client, $this->response->transferer_first_leg_bridge) : null;
$this->transfererSecondLeg = new Channel($client, $this->response->transferer_second_leg);
$this->transfererSecondLegBridge = property_exists($this->response,
'transferer_second_leg_bridge') ? new Bridge($client, $this->response->transferer_second_leg_bridge) : null;
$this->destinationApplication = $this->getResponseValue('destination_application');
$this->destinationBridge = $this->getResponseValue('destination_bridge');
$this->destinationLinkFirstLeg = $this->getResponseValue('destination_link_first_leg',
'\phparia\Resources\Channel', $client);
$this->destinationLinkSecondLeg = $this->getResponseValue('destination_link_second_leg');
$this->destinationThreewayBridge = $this->getResponseValue('destination_threeway_bridge',
'\phparia\Resources\Bridge', $client);
$this->destinationThreewayChannel = $this->getResponseValue('destination_threeway_channel',
'\phparia\Resources\Channel', $client);
$this->destinationType = $this->getResponseValue('destination_type');
$this->isExternal = $this->getResponseValue('is_external');
$this->replaceChannel = $this->getResponseValue('replace_channel', '\phparia\Resources\Channel', $client);
$this->result = $this->getResponseValue('result');
$this->transferTarget = $this->getResponseValue('transfer_target', '\phparia\Resources\Channel', $client);
$this->transferee = $this->getResponseValue('transferee', '\phparia\Resources\Channel', $client);
$this->transfererFirstLeg = $this->getResponseValue('transferer_first_leg', '\phparia\Resources\Channel',
$client);
$this->transfererFirstLegBridge = $this->getResponseValue('transferer_first_leg_bridge',
'\phparia\Resources\Bridge', $client);
$this->transfererSecondLeg = $this->getResponseValue('transferer_second_leg', '\phparia\Resources\Channel',
$client);
$this->transfererSecondLegBridge = $this->getResponseValue('transferer_second_leg_bridge',
'\phparia\Resources\Bridge', $client);
}

}
22 changes: 9 additions & 13 deletions src/wormling/phparia/Events/BridgeBlindTransfer.php
Expand Up @@ -27,7 +27,7 @@
*
* @author Brian Smith <wormling@gmail.com>
*/
class BridgeBlindTransfer extends Event
class BridgeBlindTransfer extends BridgeTransfer
{
/**
* @var Bridge (optional) - The bridge being transferred
Expand Down Expand Up @@ -141,17 +141,13 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = property_exists($this->response, 'bridge') ? new Bridge($client,
$this->response->bridge) : null;
$this->channel = new Channel($client, $this->response->channel);
$this->contex = $this->response->context;
$this->exten = $this->response->exten;
$this->isExternal = $this->response->is_external;
$this->replaceChannel = property_exists($this->response, 'replace_channel') ? new Channel($client,
$this->response->replace_channel) : null;
$this->result = $this->response->result;
$this->transferee = property_exists($this->response, 'transferee') ? new Channel($client,
$this->response->transferee) : null;
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->contex = $this->getResponseValue('context');
$this->exten = $this->getResponseValue('exten');
$this->isExternal = $this->getResponseValue('is_external');
$this->replaceChannel = $this->getResponseValue('replace_channel', '\phparia\Resources\Channel', $client);
$this->result = $this->getResponseValue('result');
$this->transferee = $this->getResponseValue('transferee', '\phparia\Resources\Channel', $client);
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/BridgeCreated.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = new Bridge($client, $this->response->bridge);
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/BridgeDestroyed.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = new Bridge($client, $this->response->bridge);
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
}

}
5 changes: 2 additions & 3 deletions src/wormling/phparia/Events/BridgeMerged.php
Expand Up @@ -67,8 +67,7 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = new Bridge($client, $this->response->bridge);
$this->bridgeFrom = new Bridge($client, $this->response->bridge_from);
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
$this->bridgeFrom = $this->getResponseValue('bridge_from', '\phparia\Resources\Bridge', $client);
}

}
7 changes: 3 additions & 4 deletions src/wormling/phparia/Events/ChannelCallerId.php
Expand Up @@ -80,9 +80,8 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->callerPresentation = $this->response->caller_presentation;
$this->callerPresentationTxt = $this->response->caller_presentation_txt;
$this->channel = new Channel($client, $this->response->channel);
$this->callerPresentation = $this->getResponseValue('caller_presentation');
$this->callerPresentationTxt = $this->getResponseValue('caller_presentation_txt');
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/ChannelConnectedLine.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
}

}
2 changes: 1 addition & 1 deletion src/wormling/phparia/Events/ChannelCreated.php
Expand Up @@ -54,7 +54,7 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->channel = $this->getResponseValue('channel', 'phparia\Resources\Channel', $client);
}

}
6 changes: 3 additions & 3 deletions src/wormling/phparia/Events/ChannelDestroyed.php
Expand Up @@ -126,9 +126,9 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->cause = $this->response->cause;
$this->causeTxt = $this->response->cause_txt;
$this->channel = new Channel($client, $this->response->channel);
$this->cause = $this->getResponseValue('cause');
$this->causeTxt = $this->getResponseValue('cause_txt');
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
}

}
6 changes: 3 additions & 3 deletions src/wormling/phparia/Events/ChannelDialplan.php
Expand Up @@ -80,8 +80,8 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->dialplanApp = $this->response->dialplan_app;
$this->dialplanAppData = $this->response->dialplan_app_data;
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->dialplanApp = $this->getResponseValue('dialplan_app');
$this->dialplanAppData = $this->getResponseValue('dialplan_app_data');
}
}
6 changes: 3 additions & 3 deletions src/wormling/phparia/Events/ChannelDtmfReceived.php
Expand Up @@ -81,9 +81,9 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->digit = $this->response->digit;
$this->durationMs = $this->response->duration_ms;
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->digit = $this->getResponseValue('digit');
$this->durationMs = $this->getResponseValue('duration_ms');
}

}
5 changes: 2 additions & 3 deletions src/wormling/phparia/Events/ChannelEnteredBridge.php
Expand Up @@ -68,8 +68,7 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = new Bridge($client, $this->response->bridge);
$this->channel = new Channel($client, $this->response->channel);
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
}

}
7 changes: 3 additions & 4 deletions src/wormling/phparia/Events/ChannelHangupRequest.php
Expand Up @@ -81,9 +81,8 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->cause = property_exists($this->response, 'cause') ? $this->response->cause : null;
$this->channel = new Channel($client, $this->response->channel);
$this->soft = property_exists($this->response, 'soft') ? $this->response->soft : null;
$this->cause = $this->getResponseValue('cause');
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->soft = $this->getResponseValue('soft');
}

}
5 changes: 2 additions & 3 deletions src/wormling/phparia/Events/ChannelLeftBridge.php
Expand Up @@ -68,8 +68,7 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = new Bridge($client, $this->response->bridge);
$this->channel = new Channel($client, $this->response->channel);
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/ChannelStateChange.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->channel = $this->getResponseValue('channel', 'phparia\Resources\Channel', $client);
}

}
5 changes: 2 additions & 3 deletions src/wormling/phparia/Events/ChannelTalkingFinished.php
Expand Up @@ -67,8 +67,7 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->duration = $this->response->duration;
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->duration = $this->getResponseValue('duration');
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/ChannelTalkingStarted.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = new Channel($client, $this->response->channel);
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
}

}
17 changes: 5 additions & 12 deletions src/wormling/phparia/Events/ChannelUserevent.php
Expand Up @@ -19,9 +19,6 @@
namespace phparia\Events;

use phparia\Client\AriClient;
use phparia\Resources\Bridge;
use phparia\Resources\Channel;
use phparia\Resources\Endpoint;

/**
* User-generated event with additional user-defined fields in the object.
Expand Down Expand Up @@ -103,14 +100,10 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->bridge = property_exists($this->response, 'bridge') ? new Bridge($client,
$this->response->bridge) : null;
$this->channel = property_exists($this->response, 'channel') ? new Channel($client,
$this->response->channel) : null;
$this->endpoint = property_exists($this->response, 'endpoint') ? new Endpoint($client,
$this->response->endpoint) : null;
$this->eventname = $this->response->eventname;
$this->userevent = $this->response->userevent;
$this->bridge = $this->getResponseValue('bridge', '\phparia\Resources\Bridge', $client);
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->endpoint = $this->getResponseValue('endpoint', '\phparia\Resources\Endpoint', $client);
$this->eventname = $this->getResponseValue('eventname');
$this->userevent = $this->getResponseValue('userevent');
}

}
8 changes: 3 additions & 5 deletions src/wormling/phparia/Events/ChannelVarset.php
Expand Up @@ -80,10 +80,8 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->channel = property_exists($this->response, 'channel') ? new Channel($client,
$this->response->channel) : null;
$this->value = property_exists($this->response, 'value') ? $this->response->value : null;
$this->variable = property_exists($this->response, 'variable') ? $this->response->variable : null;
$this->channel = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->value = $this->getResponseValue('value');
$this->variable = $this->getResponseValue('variable');
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/DeviceStateChange.php
Expand Up @@ -49,7 +49,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->deviceState = new DeviceState($client, $this->response->device_state);
$this->deviceState = $this->getResponseValue('device_state', '\phparia\Resources\DeviceState', $client);
}

}
15 changes: 6 additions & 9 deletions src/wormling/phparia/Events/Dial.php
Expand Up @@ -127,14 +127,11 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->caller = property_exists($this->response, 'channel') ? new Channel($client,
$this->response->caller) : null;
$this->dialstatus = $this->response->dialstatus;
$this->dialstring = property_exists($this->response, 'dialstring') ? $this->response->dialstring : null;
$this->forward = property_exists($this->response, 'forward') ? $this->response->forward : null;
$this->forwarded = property_exists($this->response, 'forwarded') ? new Channel($client,
$this->response->forwarded) : null;
$this->peer = $this->response->peer;
$this->caller = $this->getResponseValue('channel', '\phparia\Resources\Channel', $client);
$this->dialstatus = $this->getResponseValue('dialstatus');
$this->dialstring = $this->getResponseValue('dialstring');
$this->forward = $this->getResponseValue('forward');
$this->forwarded = $this->getResponseValue('forwarded', '\phparia\Resources\Channel', $client);
$this->peer = $this->getResponseValue('peer');
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/EndpointStateChange.php
Expand Up @@ -49,7 +49,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->endpoint = new Endpoint($client, $this->response->endpoint);
$this->endpoint = $this->getResponseValue('endpoint', '\phparia\Resources\Endpoint', $client);
}

}
6 changes: 2 additions & 4 deletions src/wormling/phparia/Events/Event.php
Expand Up @@ -102,9 +102,7 @@ public function __construct(AriClient $client, $response)

parent::__construct($response);

$this->application = $this->response->application;
$this->timestamp = property_exists($this->response,
'timestamp') ? new \DateTime($this->response->timestamp) : null;
$this->application = $this->getResponseValue('application');
$this->timestamp = $this->getResponseValue('timestamp', '\DateTime');
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/Message.php
Expand Up @@ -44,7 +44,6 @@ public function __construct($response)
{
parent::__construct($response);

$this->type = $this->response->type;
$this->type = $this->getResponseValue('type');
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/PlaybackFinished.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->playback = new Playback($client, $this->response->playback);
$this->playback = $this->getResponseValue('playback', '\phparia\Resources\Playback', $client);
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/PlaybackStarted.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->playback = new Playback($client, $this->response->playback);
$this->playback = $this->getResponseValue('playback', '\phparia\Resources\Playback', $client);
}

}
3 changes: 1 addition & 2 deletions src/wormling/phparia/Events/RecordingFailed.php
Expand Up @@ -54,7 +54,6 @@ public function __construct(AriClient $client, $response)
{
parent::__construct($client, $response);

$this->recording = new LiveRecording($client, $this->response->recording);
$this->recording = $this->getResponseValue('recording', '\phparia\Resources\LiveRecording', $client);
}

}

0 comments on commit 65ed736

Please sign in to comment.