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

Commit f1d4e0c

Browse files
authored
Merge pull request #1 from rajesh6115/master
Project Structure And Sample Class For Dialplan
2 parents 76f29ce + ac2cf5c commit f1d4e0c

11 files changed

Lines changed: 226 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
*~
3+
vendor/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
*
5+
*/
6+
7+
namespace Mobtexting\DialPlan;
8+
9+
class BasicAttribute{
10+
private $name;
11+
private $value;
12+
private $type;
13+
public function __construct($name, $value, $type="string"){
14+
$this->name = $name;
15+
$this->value = $value;
16+
$this->type = $type;
17+
}
18+
19+
public function setValue($value){
20+
if(gettype($value) === $this->type){
21+
$this->value = $value;
22+
}else{
23+
24+
}
25+
}
26+
27+
28+
public function toArray(){
29+
$result = array();
30+
switch($this->type){
31+
case 'string':
32+
$result[$this->name] = $this->value;
33+
break;
34+
case 'integer':
35+
$result[$this->name] = $this->value;
36+
break;
37+
case 'object':
38+
$result[$this->name] = $this->value.toArray();
39+
break;
40+
}
41+
return $result;
42+
}
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
namespace Mobtexting\DialPlan;
6+
class ComplexAttribute extends BasicAttribute{
7+
8+
}

Mobtexting/DialPlan/DialPlan.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Mobtexting\DialPlan;
7+
8+
abstract class DialPlan{
9+
private $name;
10+
private $attributes;
11+
private $next;
12+
13+
/**
14+
* DialPlan Constructor
15+
*
16+
* @param string $name Dial Plan Element Name
17+
* @param array $attributes Attributes of The Dial Plan Element Attributes
18+
*/
19+
20+
public function __construct($name, $attributes=NULL){
21+
$this->name = $name;
22+
if ($attributes) {
23+
$this->attributes[] = $attributes;
24+
}
25+
$this->next = array();
26+
}
27+
28+
/**
29+
*
30+
*/
31+
public function setAttribute($name, $value){
32+
$required_attribute = array_filter($this->attributes, function($attribute){
33+
return $attribute->name === 'name';
34+
});
35+
36+
$required_attribute->setValue($value);
37+
}
38+
/**
39+
* Add a Dial Plan Element
40+
*
41+
* @param DialPlan $dialplan Dial Plan to Append
42+
* @return $this
43+
*/
44+
45+
public function append($dialplan){
46+
$this->next[] = $dialplan;
47+
return $this;
48+
}
49+
50+
/**
51+
* Convert Dial Plan to json
52+
*
53+
* @return string DialPlan json representation
54+
*/
55+
56+
public function toJson(){
57+
return $this->_toString();
58+
}
59+
60+
61+
/**
62+
* Convert Dial Plan to String
63+
*
64+
* @return string DialPlan json representation
65+
*/
66+
67+
public function _toString(){
68+
$element = $this->toArray();
69+
return json_encode($element);
70+
}
71+
72+
73+
/**
74+
* Convert Dial Plan to An PHP Array
75+
*
76+
* @return Array DialPlan Array representation
77+
*/
78+
79+
public function toArray(){
80+
$element = array();
81+
$attributes= array();
82+
$result = array();
83+
foreach($this->attributes as $attribute){
84+
$attributes = array_merge($attribute->toArray(), $attributes);
85+
}
86+
$element[$this->name] = $attributes;
87+
if(count($this->next)>0){
88+
$result[] = $element;
89+
foreach($this->next as $basic_element){
90+
$result[] = $basic_element->toArray();
91+
}
92+
return $result;
93+
}else{
94+
return $element;
95+
}
96+
97+
}
98+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
*
5+
*/
6+
7+
namespace Mobtexting\DialPlan\Voice;
8+
use Mobtexting;
9+
use Mobtexting\DialPlan\DialPlan;
10+
class Answer extends DialPlan{
11+
public function __construct($delay=0){
12+
$delay_attr = new Mobtexting\DialPlan\BasicAttribute('delay', $delay, 'integer');
13+
parent::__construct("Answer", $delay_attr);
14+
}
15+
16+
public function setDelay($delay){
17+
$this->setAttribute('delay', $delay);
18+
}
19+
20+
}

Mobtexting/DialPlan/Voice/Dial.php

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
*
5+
*/
6+
7+
namespace Mobtexting\DialPlan\Voice;
8+
use Mobtexting\DialPlan\BasicAttribute;
9+
use Mobtexting\DialPlan\DialPlan;
10+
class Hangup extends DialPlan{
11+
public function __construct($reason=0){
12+
$delay_attr = new BasicAttribute('reason', $reason, 'integer');
13+
parent::__construct("Hangup", $delay_attr);
14+
}
15+
16+
public function setReason($reason){
17+
$this->setAttribute('reason', $reason);
18+
}
19+
20+
}

Mobtexting/DialPlan/Voice/Play.php

Whitespace-only changes.

Mobtexting/DialPlan/Voice/Script.php

Whitespace-only changes.

Test/index.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
require('../vendor/autoload.php');
3+
//require('Mobtexting/DialPlan/BasicAttribute.php');
4+
use Mobtexting\DialPlan\Voice\Answer;
5+
use Mobtexting\DialPlan\Voice\Hangup;
6+
$dial_plan = new Answer( 10);
7+
$dial_plan->append(new Hangup(16));
8+
print_r($dial_plan->toJson());
9+
?>

0 commit comments

Comments
 (0)