Skip to content

Commit d4da3e5

Browse files
authored
Merge pull request #71 from ethanransdellverse/verse/voice_builder_typing
Verse - Voice builder pattern and typing
2 parents 754a7ee + 6c28280 commit d4da3e5

32 files changed

+418
-209
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ try {
8383

8484
```php
8585

86-
$speakSentence = new BandwidthLib\Voice\Bxml\SpeakSentence("Hello!");
87-
$speakSentence->voice("susan");
88-
$speakSentence->locale("en_US");
89-
$speakSentence->gender("female");
90-
$response = new BandwidthLib\Voice\Bxml\Response();
91-
$response->addVerb($speakSentence);
86+
$speakSentence = BandwidthLib\Voice\Bxml\SpeakSentence::make("Hello!")
87+
->voice("susan")
88+
->locale("en_US")
89+
->gender("female");
90+
$response = BandwidthLib\Voice\Bxml\Response::make()
91+
->addVerb($speakSentence);
9292
echo $response->toBxml();
9393
```
9494

src/Voice/Bxml/Bridge.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace BandwidthLib\Voice\Bxml;
1111

1212
use DOMDocument;
13+
use DOMElement;
1314

1415
require_once "Verb.php";
1516

@@ -85,119 +86,132 @@ public function __construct(string $targetCall) {
8586
*
8687
* @param string $bridgeCompleteUrl URL to send the bridge complete event to
8788
*/
88-
public function bridgeCompleteUrl(string $bridgeCompleteUrl) {
89+
public function bridgeCompleteUrl(string $bridgeCompleteUrl): Bridge {
8990
$this->bridgeCompleteUrl = $bridgeCompleteUrl;
91+
return $this;
9092
}
9193

9294
/**
9395
* Sets the bridgeCompleteMethod attribute for Bridge
9496
*
9597
* @param string $bridgeCompleteMethod HTTP method to send the bridge complete event
9698
*/
97-
public function bridgeCompleteMethod(string $bridgeCompleteMethod) {
99+
public function bridgeCompleteMethod(string $bridgeCompleteMethod): Bridge {
98100
$this->bridgeCompleteMethod = $bridgeCompleteMethod;
101+
return $this;
99102
}
100103

101104
/**
102105
* Sets the bridgeTargetCompleteUrl attribute for Bridge
103106
*
104107
* @param string $bridgeTargetCompleteUrl URL to send the bridge target complete event to
105108
*/
106-
public function bridgeTargetCompleteUrl(string $bridgeTargetCompleteUrl) {
109+
public function bridgeTargetCompleteUrl(string $bridgeTargetCompleteUrl): Bridge {
107110
$this->bridgeTargetCompleteUrl = $bridgeTargetCompleteUrl;
111+
return $this;
108112
}
109113

110114
/**
111115
* Sets the bridgeTargetCompleteMethod attribute for Bridge
112116
*
113117
* @param string $bridgeTargetCompleteMethod HTTP method to send the bridge target complete event
114118
*/
115-
public function bridgeTargetCompleteMethod(string $bridgeTargetCompleteMethod) {
119+
public function bridgeTargetCompleteMethod(string $bridgeTargetCompleteMethod): Bridge {
116120
$this->bridgeTargetCompleteMethod = $bridgeTargetCompleteMethod;
121+
return $this;
117122
}
118123

119124
/**
120125
* Sets the username attribute for Bridge
121126
*
122127
* @param string $username HTTP basic auth username for sending events
123128
*/
124-
public function username(string $username) {
129+
public function username(string $username): Bridge {
125130
$this->username = $username;
131+
return $this;
126132
}
127133

128134
/**
129135
* Sets the password attribute for Bridge
130136
*
131137
* @param string $password HTTP basic auth password for sending events
132138
*/
133-
public function password(string $password) {
139+
public function password(string $password): Bridge {
134140
$this->password = $password;
141+
return $this;
135142
}
136143

137144
/**
138145
* Sets the tag attribute for Bridge
139146
*
140147
* @param string $tag String to include in events
141148
*/
142-
public function tag(string $tag) {
149+
public function tag(string $tag): Bridge {
143150
$this->tag = $tag;
151+
return $this;
144152
}
145153

146154
/**
147155
* Sets the bridgeCompleteFallbackUrl attribute for Bridge
148156
*
149157
* @param string $bridgeCompleteFallbackUrl Fallback URL for bridge complete callback events
150158
*/
151-
public function bridgeCompleteFallbackUrl(string $bridgeCompleteFallbackUrl) {
159+
public function bridgeCompleteFallbackUrl(string $bridgeCompleteFallbackUrl): Bridge {
152160
$this->bridgeCompleteFallbackUrl = $bridgeCompleteFallbackUrl;
161+
return $this;
153162
}
154163

155164
/**
156165
* Sets the bridgeCompleteFallbackMethod attribute for Bridge
157166
*
158167
* @param string $bridgeCompleteFallbackMethod HTTP method for bridge complete fallback requests
159168
*/
160-
public function bridgeCompleteFallbackMethod(string $bridgeCompleteFallbackMethod) {
169+
public function bridgeCompleteFallbackMethod(string $bridgeCompleteFallbackMethod): Bridge {
161170
$this->bridgeCompleteFallbackMethod = $bridgeCompleteFallbackMethod;
171+
return $this;
162172
}
163173

164174
/**
165175
* Sets the bridgeTargetCompleteFallbackUrl attribute for Bridge
166176
*
167177
* @param string $bridgeTargetCompleteFallbackUrl Fallback URL for bridge target complete callback events
168178
*/
169-
public function bridgeTargetCompleteFallbackUrl(string $bridgeTargetCompleteFallbackUrl) {
179+
public function bridgeTargetCompleteFallbackUrl(string $bridgeTargetCompleteFallbackUrl): Bridge {
170180
$this->bridgeTargetCompleteFallbackUrl = $bridgeTargetCompleteFallbackUrl;
181+
return $this;
171182
}
172183

173184
/**
174185
* Sets the bridgeTargetCompleteFallbackMethod attribute for Bridge
175186
*
176187
* @param string $bridgeTargetCompleteFallbackMethod HTTP method for bridge target complete fallback events
177188
*/
178-
public function bridgeTargetCompleteFallbackMethod(string $bridgeTargetCompleteFallbackMethod) {
189+
public function bridgeTargetCompleteFallbackMethod(string $bridgeTargetCompleteFallbackMethod): Bridge {
179190
$this->bridgeTargetCompleteFallbackMethod = $bridgeTargetCompleteFallbackMethod;
191+
return $this;
180192
}
181193

182194
/**
183195
* Sets the fallbackUsername attribute for Bridge
184196
*
185197
* @param string $fallbackUsername HTTP basic auth username for fallback events
186198
*/
187-
public function fallbackUsername(string $fallbackUsername) {
199+
public function fallbackUsername(string $fallbackUsername): Bridge {
188200
$this->fallbackUsername = $fallbackUsername;
201+
return $this;
189202
}
190203

191204
/**
192205
* Sets the fallbackPassword attribute for Bridge
193206
*
194207
* @param string $fallbackPassword HTTP basic auth password
195208
*/
196-
public function fallbackPassword(string $fallbackPassword) {
209+
public function fallbackPassword(string $fallbackPassword): Bridge {
197210
$this->fallbackPassword = $fallbackPassword;
211+
return $this;
198212
}
199213

200-
public function toBxml(DOMDocument $doc) {
214+
public function toBxml(DOMDocument $doc): DOMElement {
201215
$element = $doc->createElement("Bridge");
202216

203217
$element->appendChild($doc->createTextNode($this->targetCall));

src/Voice/Bxml/Bxml.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ public function __construct() {
2929
*
3030
* @param Verb $verb The verb to add to the list
3131
*/
32-
public function addVerb(Verb $verb) {
32+
public function addVerb(Verb $verb): Bxml {
3333
array_push($this->verbs, $verb);
34+
return $this;
3435
}
3536

3637
/**
3738
* Converts the Response class into its BXML representation
3839
*
3940
* @return string The xml representation of the class
4041
*/
41-
public function toBxml() {
42+
public function toBxml(): string {
4243
$ssmlRegex = '/<([a-zA-Z\/\/].*?)>/';
4344
$doc = new DOMDocument('1.0', 'UTF-8');
4445
$bxmlElement = $doc->createElement("Bxml");

src/Voice/Bxml/Conference.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace BandwidthLib\Voice\Bxml;
1111

1212
use DOMDocument;
13+
use DOMElement;
1314

1415
require_once "Verb.php";
1516

@@ -81,119 +82,132 @@ public function __construct(string $conferenceName) {
8182
*
8283
* @param string $tag A custom string to be included in callbacks
8384
*/
84-
public function tag(string $tag) {
85+
public function tag(string $tag): Conference {
8586
$this->tag = $tag;
87+
return $this;
8688
}
8789

8890
/**
8991
* Sets the username attribute for Conference
9092
*
9193
* @param string $username Username for basic auth for callbacks
9294
*/
93-
public function username(string $username) {
95+
public function username(string $username): Conference {
9496
$this->username = $username;
97+
return $this;
9598
}
9699

97100
/**
98101
* Sets the password attribute for Conference
99102
*
100103
* @param string $password Password for basic auth for callbacks
101104
*/
102-
public function password(string $password) {
105+
public function password(string $password): Conference {
103106
$this->password = $password;
107+
return $this;
104108
}
105109

106110
/**
107111
* Sets the conferenceEventUrl attribute for Conference
108112
*
109113
* @param string $conferenceEventUrl URL to receive conference events
110114
*/
111-
public function conferenceEventUrl(string $conferenceEventUrl) {
115+
public function conferenceEventUrl(string $conferenceEventUrl): Conference {
112116
$this->conferenceEventUrl = $conferenceEventUrl;
117+
return $this;
113118
}
114119

115120
/**
116121
* Sets the conferenceEventMethod attribute for Conference
117122
*
118123
* @param string $conferenceEventMethod HTTP method for conference events
119124
*/
120-
public function conferenceEventMethod(string $conferenceEventMethod) {
125+
public function conferenceEventMethod(string $conferenceEventMethod): Conference {
121126
$this->conferenceEventMethod = $conferenceEventMethod;
127+
return $this;
122128
}
123129

124130
/**
125131
* Sets the callIdsToCoach attribute for Conference
126132
*
127133
* @param string $callIdsToCoach A string of comma separated call IDs to coach
128134
*/
129-
public function callIdsToCoach(string $callIdsToCoach) {
135+
public function callIdsToCoach(string $callIdsToCoach): Conference {
130136
$this->callIdsToCoach = $callIdsToCoach;
137+
return $this;
131138
}
132139

133140
/**
134141
* Sets the callIdsToCoach attribute for Conference
135142
*
136143
* @param array $callIdsToCoach An array of call IDs to coach
137144
*/
138-
public function callIdsToCoachArray(array $callIdsToCoach) {
145+
public function callIdsToCoachArray(array $callIdsToCoach): Conference {
139146
$this->callIdsToCoach = implode(",", $callIdsToCoach);
147+
return $this;
140148
}
141149

142150
/**
143151
* Sets the mute attribute for Conference
144152
*
145153
* @param boolean $mute Determines if conference members should be on mute
146154
*/
147-
public function mute(bool $mute) {
155+
public function mute(bool $mute): Conference {
148156
$this->mute = $mute;
157+
return $this;
149158
}
150159

151160
/**
152161
* Sets the hold attribute for Conference
153162
*
154163
* @param boolean $hold Determines if conference members should be on hold
155164
*/
156-
public function hold(bool $hold) {
165+
public function hold(bool $hold): Conference {
157166
$this->hold = $hold;
167+
return $this;
158168
}
159169

160170
/**
161171
* Sets the conferenceEventFallbackUrl attribute for Conference
162172
*
163173
* @param string $conferenceEventFallbackUrl Fallback url for conference events
164174
*/
165-
public function conferenceEventFallbackUrl(string $conferenceEventFallbackUrl) {
175+
public function conferenceEventFallbackUrl(string $conferenceEventFallbackUrl): Conference {
166176
$this->conferenceEventFallbackUrl = $conferenceEventFallbackUrl;
177+
return $this;
167178
}
168179

169180
/**
170181
* Sets the conferenceEventFallbackMethod attribute for Conference
171182
*
172183
* @param string $conferenceEventFallbackMethod HTTP method for fallback events
173184
*/
174-
public function conferenceEventFallbackMethod(string $conferenceEventFallbackMethod) {
185+
public function conferenceEventFallbackMethod(string $conferenceEventFallbackMethod): Conference {
175186
$this->conferenceEventFallbackMethod = $conferenceEventFallbackMethod;
187+
return $this;
176188
}
177189

178190
/**
179191
* Sets the fallbackUsername attribute for Conference
180192
*
181193
* @param string $fallbackUsername HTTP basic auth username for fallback events
182194
*/
183-
public function fallbackUsername(string $fallbackUsername) {
195+
public function fallbackUsername(string $fallbackUsername): Conference {
184196
$this->fallbackUsername = $fallbackUsername;
197+
return $this;
185198
}
186199

187200
/**
188201
* Sets the fallbackPassword attribute for Conference
189202
*
190203
* @param string $fallbackPassword HTTP basic auth password for fallback events
191204
*/
192-
public function fallbackPassword(string $fallbackPassword) {
205+
public function fallbackPassword(string $fallbackPassword): Conference {
193206
$this->fallbackPassword = $fallbackPassword;
207+
return $this;
194208
}
195209

196-
public function toBxml(DOMDocument $doc) {
210+
public function toBxml(DOMDocument $doc): DOMElement {
197211
$element = $doc->createElement("Conference");
198212

199213
$element->appendChild($doc->createTextNode($this->conferenceName));

src/Voice/Bxml/CustomParam.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace BandwidthLib\Voice\Bxml;
1111

1212
use DOMDocument;
13+
use DOMElement;
1314

1415
require_once "Verb.php";
1516

@@ -28,20 +29,22 @@ class CustomParam extends Verb {
2829
*
2930
* @param string $name (required) The name of this parameter, up to 256 characters.
3031
*/
31-
public function name(string $name) {
32+
public function name(string $name): CustomParam {
3233
$this->name = $name;
34+
return $this;
3335
}
3436

3537
/**
3638
* Sets the value attribute for CustomParam
3739
*
3840
* @param string $value (required) The value of this parameter, up to 2048 characters.
3941
*/
40-
public function value(string $value) {
42+
public function value(string $value): CustomParam {
4143
$this->value = $value;
44+
return $this;
4245
}
4346

44-
public function toBxml(DOMDocument $doc) {
47+
public function toBxml(DOMDocument $doc): DOMElement {
4548
$element = $doc->createElement("CustomParam");
4649

4750
if(isset($this->name)) {

0 commit comments

Comments
 (0)