Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch-contrib
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch-contrib
Commits
93d11bb9
提交
93d11bb9
authored
1月 18, 2012
作者:
Raymond Chandler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initial checkin of phttapi.php library for writing httapi apps
上级
ee7fb354
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
310 行增加
和
0 行删除
+310
-0
phttapi.php
intralanman/PHP/phttapi/phttapi.php
+310
-0
没有找到文件。
intralanman/PHP/phttapi/phttapi.php
0 → 100644
浏览文件 @
93d11bb9
<?php
class
NotImplementedException
extends
Exception
{}
class
NullDataException
extends
Exception
{}
class
phttapi_xml_blob
{
public
$xml
;
public
function
__construct
()
{
$this
->
xml
=
new
XMLWriter
();
$this
->
xml
->
openMemory
();
}
public
function
output
()
{
$this
->
xml
->
endElement
();
$xml
=
$this
->
xml
->
outputMemory
();
return
$xml
;
}
public
function
open
(
$tag
)
{
$this
->
xml
->
startElement
(
$tag
);
}
public
function
text
(
$text
)
{
$this
->
xml
->
text
(
$text
);
}
public
function
close
()
{
$this
->
xml
->
endElement
();
}
public
function
attr
(
$key
,
$val
)
{
$this
->
xml
->
writeAttribute
(
$key
,
$val
);
}
public
function
raw
(
$xml
)
{
$this
->
xml
->
writeRaw
(
"
$xml
"
);
}
}
class
phttapi
extends
phttapi_xml_blob
{
public
function
__construct
()
{
parent
::
__construct
();
$this
->
xml
->
setIndent
(
true
);
$this
->
xml
->
setIndentString
(
' '
);
$this
->
open
(
'document'
);
$this
->
attr
(
'type'
,
'text/freeswitch-httapi'
);
}
public
function
start_work
()
{
$this
->
open
(
'work'
);
}
public
function
end_work
()
{
$this
->
close
();
}
public
function
start_variables
()
{
$this
->
open
(
'variables'
);
}
public
function
add_variable
(
$var
,
$val
)
{
$this
->
open
(
$var
);
$this
->
text
(
$val
);
$this
->
close
();
}
public
function
end_variables
()
{
$this
->
close
();
}
public
function
start_params
()
{
$this
->
open
(
'params'
);
}
public
function
add_param
(
$param
,
$value
)
{
$this
->
open
(
$param
);
$this
->
text
(
$value
);
$this
->
close
();
}
public
function
end_params
()
{
$this
->
close
();
}
public
function
add_action
(
$action
)
{
$xml
=
$action
->
output
();
$this
->
raw
(
$xml
);
}
}
class
phttapi_action
extends
phttapi_xml_blob
{
private
$action_text
=
null
;
public
function
__call
(
$method
,
$args
)
{
$attribute
=
preg_replace
(
'/_/'
,
'-'
,
$method
);
if
(
property_exists
(
$this
,
'attributes'
)
&&
is_array
(
$this
->
attributes
)
&&
array_key_exists
(
$attribute
,
$this
->
attributes
)
&&
!
empty
(
$this
->
attributes
[
$attribute
]
)
)
{
if
(
!
count
(
$args
)
)
{
throw
new
NullDataException
(
"
$method
requires an argument"
);
}
$value
=
$args
[
0
];
$this
->
attr
(
$attribute
,
$value
);
}
else
{
throw
new
NotImplementedException
(
sprintf
(
"%s doesn't implement %s"
,
get_class
(
$this
),
$method
)
);
}
}
public
function
__construct
(
$text
=
null
)
{
parent
::
__construct
();
$this
->
open
(
preg_replace
(
'/^phttapi_/'
,
''
,
get_class
(
$this
)
)
);
$this
->
action_text
=
$text
;
}
public
function
action
(
$value
)
{
$this
->
attr
(
preg_replace
(
'/_/'
,
'-'
,
__FUNCTION__
),
$value
);
}
public
function
temp_action
(
$value
)
{
$this
->
attr
(
preg_replace
(
'/_/'
,
'-'
,
__FUNCTION__
),
$value
);
}
public
function
name
(
$value
)
{
$this
->
attr
(
preg_replace
(
'/_/'
,
'-'
,
__FUNCTION__
),
$value
);
}
public
function
output
()
{
if
(
$this
->
action_text
)
{
$this
->
text
(
$this
->
action_text
);
}
return
parent
::
output
();
}
}
class
phttapi_action_binding
extends
phttapi_xml_blob
{
public
$action_text
;
public
function
__construct
(
$text
=
null
)
{
if
(
!
$text
)
throw
new
NullDataException
(
'match digits must be passed'
);
parent
::
__construct
();
$this
->
open
(
'binding'
);
$this
->
action_text
=
$text
;
}
public
function
strip
(
$value
)
{
$this
->
attr
(
preg_replace
(
'/_/'
,
'-'
,
__FUNCTION__
),
$value
);
}
public
function
output
()
{
$this
->
raw
(
$this
->
action_text
);
$this
->
raw
(
'blah WTF'
);
parent
::
output
();
}
}
class
phttapi_prompt
extends
phttapi_action
{
public
function
add_binding
(
$binding
)
{
$xml
=
$binding
->
output
();
if
(
get_class
(
$binding
)
==
'phttapi_action_binding'
)
{
$this
->
raw
(
$xml
);
}
}
}
// ACTIONS
class
phttapi_break
extends
phttapi_action
{}
class
phttapi_conference
extends
phttapi_action
{
public
$attributes
=
array
(
'profile'
=>
true
,
);
}
class
phttapi_continue
extends
phttapi_action
{}
class
phttapi_dial
extends
phttapi_action
{
public
$attributes
=
array
(
'context'
=>
true
,
'dialplan'
=>
true
,
'caller_id_name'
=>
true
,
'caller_id_number'
=>
true
,
);
public
function
__construct
(
$text
=
null
)
{
if
(
!
$text
)
throw
new
NullDataException
(
"no data passed"
);
}
}
class
phttapi_execute
extends
phttapi_action
{
public
function
application
(
$app
,
$data
)
{
$this
->
open
(
$app
);
$this
->
text
(
$data
);
}
}
if
(
class_exists
(
'PHPUnit_Framework_TestCase'
)
)
{
class
phttapi_executeTest
extends
PHPUnit_Framework_TestCase
{
/**
* @expectedException NullDataException
*/
public
function
testNoData
()
{
$e
=
new
phttapi_execute
();
}
/**
* @expectedException NotImplementedException
*/
public
function
testFileThrowsException
()
{
$e
=
new
phttapi_execute
(
'text'
);
$e
->
file
();
}
}
}
class
phttapi_getVar
extends
phttapi_action
{
public
$attributes
=
array
(
'permanent'
=>
true
,
);
public
function
__construct
(
$text
=
null
)
{
if
(
!
$text
)
throw
new
NullDataException
(
"no data passed"
);
}
}
class
phttapi_hangup
extends
phttapi_action
{
public
$attributes
=
array
(
'cause'
=>
true
,
);
}
class
phttapi_log
extends
phttapi_action
{
public
$attributes
=
array
(
'level'
=>
true
,
'clean'
=>
true
,
);
}
class
phttapi_pause
extends
phttapi_action
{
public
$attributes
=
array
(
'milliseconds'
=>
true
,
);
}
class
phttapi_playback
extends
phttapi_prompt
{
public
$attributes
=
array
(
'file'
=>
true
,
'error-file'
=>
true
,
'digit-timeout'
=>
true
,
'input-timeout'
=>
true
,
'loops'
=>
true
,
'asr-engine'
=>
true
,
'asr-grammar'
=>
true
,
);
}
class
phttapi_record
extends
phttapi_prompt
{
public
$attributes
=
array
(
'file'
=>
true
,
'error-file'
=>
true
,
'digit-timeout'
=>
true
,
'input-timeout'
=>
true
,
'loops'
=>
true
,
);
}
class
phttapi_recordCall
extends
phttapi_action
{
public
$attributes
=
array
(
'limit'
=>
true
,
);
}
class
phttapi_say
extends
phttapi_action
{
public
$attributes
=
array
(
'gender'
=>
true
,
'method'
=>
true
,
'type'
=>
true
,
'language'
=>
true
,
);
}
class
phttapi_speak
extends
phttapi_action
{
public
$attributes
=
array
(
'engine'
=>
true
,
'voice'
=>
true
,
);
}
class
phttapi_sms
extends
phttapi_action
{
public
$attributes
=
array
(
'to'
=>
true
,
);
public
function
__construct
(
$text
=
null
)
{
if
(
!
$text
)
throw
new
Exception
(
"no data passed"
);
}
}
class
phttapi_voicemail
extends
phttapi_action
{
public
$attributes
=
array
(
'auth-only'
=>
true
,
'domain'
=>
true
,
'profile'
=>
true
,
'check'
=>
true
,
'id'
=>
true
,
);
}
/*
*/
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论