Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Commit 295eeee

Browse files
authored
Merge pull request #6 from rajesh6115/master
menu widget corrected
2 parents a881a87 + 056ae19 commit 295eeee

5 files changed

Lines changed: 50 additions & 55 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"minimum-stability": "dev",
1313
"require": {
14-
"php": ">= 5.6"
14+
"php": ">= 5.5"
1515
},
1616
"autoload": {
1717
"psr-4": {

src/Voice/Tag/Dial.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,16 @@ public function __construct($to, $from = null)
1919

2020
public function onAnswer($tag, $attribs = [], $isSequential = false)
2121
{
22-
$newTag = $this->append($tag, $attribs);
23-
if($isSequential){
24-
$this->attributes['onanswer'] = array_merge($this->attributes['onanswer'], array($newTag) );
25-
}else {
26-
$this->setAttribute('onanswer', array($newTag), true);
27-
}
28-
return $newTag;
22+
$new_tag = $this->append($tag, $attribs);
23+
$this->setAttribute('onanswer', array($new_tag), false);
24+
return $new_tag;
2925
}
3026

3127
public function onNoAnswer($tag, $attribs = [], $isSequential = false)
3228
{
33-
$newTag = $this->append($tag, $attribs);
34-
if($isSequential){
35-
$this->attributes['onnoanswer'] = array_merge($this->attributes['onnoanswer'], array($newTag) );
36-
}else {
37-
$this->setAttribute('onnoanswer', array($newTag), true);
38-
}
39-
return $newTag;
40-
}
41-
42-
public function noAnswer($tag, $attribs = [], $isSequential = false)
43-
{
44-
$newTag = $this->append($tag, $attribs);
45-
if($isSequential){
46-
$this->attributes['onnoanswer'] = array_merge($this->attributes['onnoanswer'], array($newTag) );
47-
}else {
48-
$this->setAttribute('onnoanswer', array($newTag), true);
49-
}
50-
return $newTag;
29+
$new_tag = $this->append($tag, $attribs);
30+
$this->setAttribute('onnoanswer', array($new_tag), false);
31+
return $new_tag;
5132
}
5233

5334
public function getDefaultAttributes()

src/Voice/Tag/Menu.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,54 @@ class Menu extends Voice
1313
'onfail'
1414
];
1515

16-
public function __construct($prompt, $attribs = [])
16+
public function __construct($prompt = null, $attribs = [])
1717
{
18+
if ($prompt) {
19+
if (is_array($prompt)) {
20+
$attribs = array_merge($prompt, $attribs);
21+
} else {
22+
$attribs['prompt'] = $prompt;
23+
}
24+
}
25+
1826
parent::__construct("Menu", $attribs);
1927
}
2028

2129
public function onFail($verb, $attribs = [], $isSequential = false)
2230
{
23-
$newTag = $this->append($verb, $attribs);
24-
if($isSequential){
25-
$this->attributes['onfail'] = array_merge($this->attributes['onfail'], array($newTag) );
26-
}else {
27-
$this->setAttribute('onfail', array($newTag), true);
28-
}
29-
return $newTag;
31+
$new_tag = $this->append($verb, $attribs);
32+
$this->setAttribute('onfail', array($new_tag), false);
33+
return $new_tag;
3034
}
3135

32-
public function onTimeout($verb, $attribs = [], $isSequential = false)
36+
public function onKeyPress($key, $verb, $attribs = [])
3337
{
34-
$newTag = $this->append($verb, $attribs);
35-
if($isSequential){
36-
$this->attributes['timeout'] = array_merge($this->attributes['timeout'], array($newTag) );
37-
}else {
38-
$this->setAttribute('timeout', array($newTag), true);
39-
}
38+
$new_tag = $this->append($verb, $attribs);
39+
$this->setAttribute($key, array($new_tag), false);
40+
return $new_tag;
41+
}
42+
public function onWrongKey($verb, $attribs = [])
43+
{
44+
$new_tag = $this->append($verb, $attribs);
45+
$this->setAttribute('wrongkey', array($new_tag), false);
46+
return $new_tag;
47+
}
4048

41-
return $newTag;
49+
public function onTimeout($verb, $attribs = [], $isSequential = false)
50+
{
51+
$new_tag = $this->append($verb, $attribs);
52+
$this->setAttribute('timeout', array($new_tag), false);
53+
return $new_tag;
4254
}
4355

4456
public function getDefaultAttributes()
4557
{
4658
return [
47-
'waittime' => 10,
48-
'maxrepeat' => 3,
49-
'type' => 'parallel',
50-
'dtmftimeout' => 3,
51-
'dtmftdefaultkey' => ''
59+
'waittime' => 10,
60+
'maxrepeat' => 3,
61+
'type' => 'parallel',
62+
'dtmftimeout' => 3,
63+
'dtmfdefaultkey' => ''
5264
];
5365
}
5466
}

src/Voice/Tag/Url.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public function __construct($url = null, $response = [])
1414

1515
public function onResponse($value, $tag)
1616
{
17-
return $this->setAttribute([
18-
'response' => [$value => $this->append($tag)]
17+
$new_tag = $this->append($tag);
18+
$this->setAttribute([
19+
'response' => [$value => array($new_tag)]
1920
], null, true);
21+
return $new_tag;
2022
}
2123

2224
public function getDefaultAttributes()

src/Voice/Voice.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
class Voice
88
{
99
protected $name;
10-
protected $append = [];
10+
protected $append = [];
1111
protected $attributes = [];
12-
protected $nested = [];
12+
protected $nested = [];
1313

1414
/**
1515
* DialPlan Constructor
@@ -44,13 +44,13 @@ public function setAttribute($name, $value = null, $instance = false)
4444
if ($instance) {
4545
return $value;
4646
}
47-
47+
4848
return $this;
4949
}
50-
50+
5151
public function append($verb, $args = [])
5252
{
53-
$widget = 'Mobtexting\\Voice\\Tag\\'.ucfirst(strtolower($verb));
53+
$widget = 'Mobtexting\\Voice\\Tag\\' . ucfirst(strtolower($verb));
5454

5555
$widget = new $widget(...$args);
5656

@@ -94,7 +94,7 @@ public function toArray()
9494
$element = array();
9595
$attributes = $this->getDefaultAttributes();
9696

97-
$attributes = array_merge($attributes, $this->processAttribs($this->attributes));
97+
$attributes = array_replace($attributes, $this->processAttribs($this->attributes));
9898

9999
$element[$this->name] = $attributes;
100100

0 commit comments

Comments
 (0)