Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
easy-sms
提交
639d1cdf
E
easy-sms
项目概览
OpenDocCN
/
easy-sms
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easy-sms
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
639d1cdf
编写于
3月 22, 2019
作者:
O
overtrue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve class validation.
上级
322dd21f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
33 addition
and
22 deletion
+33
-22
src/EasySms.php
src/EasySms.php
+15
-15
src/Gateways/AliyunrestGateway.php
src/Gateways/AliyunrestGateway.php
+1
-1
src/PhoneNumber.php
src/PhoneNumber.php
+1
-1
tests/EasySmsTest.php
tests/EasySmsTest.php
+15
-4
tests/Traits/HasHttpRequestTest.php
tests/Traits/HasHttpRequestTest.php
+1
-1
未找到文件。
src/EasySms.php
浏览文件 @
639d1cdf
...
...
@@ -126,15 +126,15 @@ class EasySms
*/
public
function
strategy
(
$strategy
=
null
)
{
if
(
is_null
(
$strategy
))
{
if
(
\
is_null
(
$strategy
))
{
$strategy
=
$this
->
config
->
get
(
'default.strategy'
,
OrderStrategy
::
class
);
}
if
(
!
class_exists
(
$strategy
))
{
$strategy
=
__NAMESPACE__
.
'\Strategies\\'
.
ucfirst
(
$strategy
);
if
(
!
\
class_exists
(
$strategy
))
{
$strategy
=
__NAMESPACE__
.
'\Strategies\\'
.
\
ucfirst
(
$strategy
);
}
if
(
!
class_exists
(
$strategy
))
{
if
(
!
\
class_exists
(
$strategy
))
{
throw
new
InvalidArgumentException
(
"Unsupported strategy
\"
{
$strategy
}
\"
"
);
}
...
...
@@ -227,7 +227,7 @@ class EasySms
}
if
(
!
(
$gateway
instanceof
GatewayInterface
))
{
throw
new
InvalidArgumentException
(
sprintf
(
'Gateway "%s" not inherited
from %s.'
,
$name
,
GatewayInterface
::
class
));
throw
new
InvalidArgumentException
(
\
sprintf
(
'Gateway "%s" must be inherit
from %s.'
,
$name
,
GatewayInterface
::
class
));
}
return
$gateway
;
...
...
@@ -245,8 +245,8 @@ class EasySms
*/
protected
function
makeGateway
(
$gateway
,
$config
)
{
if
(
!
class_exists
(
$gateway
))
{
throw
new
InvalidArgumentException
(
sprintf
(
'Gateway "%s" not exists
.'
,
$gateway
));
if
(
!
\
class_exists
(
$gateway
)
||
!
\
in_array
(
GatewayInterface
::
class
,
\
class_implements
(
$gateway
)
))
{
throw
new
InvalidArgumentException
(
\
sprintf
(
'Class "%s" is a invalid easy-sms gateway
.'
,
$gateway
));
}
return
new
$gateway
(
$config
);
...
...
@@ -261,11 +261,11 @@ class EasySms
*/
protected
function
formatGatewayClassName
(
$name
)
{
if
(
class_exists
(
$name
))
{
if
(
\
class_exists
(
$name
))
{
return
$name
;
}
$name
=
ucfirst
(
str_replace
([
'-'
,
'_'
,
''
],
''
,
$name
));
$name
=
\
ucfirst
(
\
str_replace
([
'-'
,
'_'
,
''
],
''
,
$name
));
return
__NAMESPACE__
.
"
\\
Gateways
\\
{
$name
}
Gateway"
;
}
...
...
@@ -279,7 +279,7 @@ class EasySms
*/
protected
function
callCustomCreator
(
$gateway
)
{
return
call_user_func
(
$this
->
customCreators
[
$gateway
],
$this
->
config
->
get
(
"gateways.
{
$gateway
}
"
,
[]));
return
\
call_user_func
(
$this
->
customCreators
[
$gateway
],
$this
->
config
->
get
(
"gateways.
{
$gateway
}
"
,
[]));
}
/**
...
...
@@ -293,7 +293,7 @@ class EasySms
return
$number
;
}
return
new
PhoneNumber
(
trim
(
$number
));
return
new
PhoneNumber
(
\
trim
(
$number
));
}
/**
...
...
@@ -304,7 +304,7 @@ class EasySms
protected
function
formatMessage
(
$message
)
{
if
(
!
(
$message
instanceof
MessageInterface
))
{
if
(
!
is_array
(
$message
))
{
if
(
!
\
is_array
(
$message
))
{
$message
=
[
'content'
=>
$message
,
'template'
=>
$message
,
...
...
@@ -329,7 +329,7 @@ class EasySms
$formatted
=
[];
foreach
(
$gateways
as
$gateway
=>
$setting
)
{
if
(
is_int
(
$gateway
)
&&
is_string
(
$setting
))
{
if
(
\
is_int
(
$gateway
)
&&
\
is_string
(
$setting
))
{
$gateway
=
$setting
;
$setting
=
[];
}
...
...
@@ -337,8 +337,8 @@ class EasySms
$formatted
[
$gateway
]
=
$setting
;
$globalSettings
=
$this
->
config
->
get
(
"gateways.
{
$gateway
}
"
,
[]);
if
(
is_string
(
$gateway
)
&&
!
empty
(
$globalSettings
)
&&
is_array
(
$setting
))
{
$formatted
[
$gateway
]
=
new
Config
(
array_merge
(
$globalSettings
,
$setting
));
if
(
\
is_string
(
$gateway
)
&&
!
empty
(
$globalSettings
)
&&
\
is_array
(
$setting
))
{
$formatted
[
$gateway
]
=
new
Config
(
\
array_merge
(
$globalSettings
,
$setting
));
}
}
...
...
src/Gateways/AliyunrestGateway.php
浏览文件 @
639d1cdf
...
...
@@ -67,7 +67,7 @@ class AliyunrestGateway extends Gateway
$result
=
$this
->
post
(
$this
->
getEndpointUrl
(
$urlParams
),
$params
);
if
(
isset
(
$result
[
'error_response'
])
&&
$result
[
'error_response'
][
'code'
]
!=
0
)
{
if
(
isset
(
$result
[
'error_response'
])
&&
0
!=
$result
[
'error_response'
][
'code'
]
)
{
throw
new
GatewayErrorException
(
$result
[
'error_response'
][
'msg'
],
$result
[
'error_response'
][
'code'
],
$result
);
}
...
...
src/PhoneNumber.php
浏览文件 @
639d1cdf
...
...
@@ -83,7 +83,7 @@ class PhoneNumber implements \Overtrue\EasySms\Contracts\PhoneNumberInterface
/**
* @param string $prefix
*
* @return
null|string
* @return
string|null
*/
public
function
getPrefixedIDDCode
(
$prefix
)
{
...
...
tests/EasySmsTest.php
浏览文件 @
639d1cdf
...
...
@@ -32,11 +32,19 @@ class EasySmsTest extends TestCase
// invalid gateway
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'
Gateway "Overtrue\EasySms\Gateways\NotExistsGatewayNameGateway" not exists
.'
);
$this
->
expectExceptionMessage
(
'
Class "Overtrue\EasySms\Gateways\NotExistsGatewayNameGateway" is a invalid easy-sms gateway
.'
);
$easySms
->
gateway
(
'NotExistsGatewayName'
);
}
public
function
testGatewayNameConflicts
()
{
$easySms
=
\
Mockery
::
mock
(
EasySms
::
class
.
'[makeGateway]'
,
[[
'default'
=>
DummyGatewayForTest
::
class
]]);
$this
->
expectExceptionMessage
(
'Class "Overtrue\EasySms\Tests\DummyGatewayNotImplementsGatewayInterface" is a invalid easy-sms gateway.'
);
$easySms
->
makeGateway
(
DummyGatewayNotImplementsGatewayInterface
::
class
,
[]);
}
public
function
testGatewayWithoutDefaultSetting
()
{
$easySms
=
new
EasySms
([]);
...
...
@@ -58,9 +66,8 @@ class EasySmsTest extends TestCase
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
sprintf
(
'Gateway "%s" not inherited from %s.'
,
DummyInvalidGatewayForTest
::
class
,
GatewayInterface
::
class
'Class "%s" is a invalid easy-sms gateway.'
,
DummyInvalidGatewayForTest
::
class
)
);
$easySms
->
gateway
();
...
...
@@ -181,6 +188,10 @@ class EasySmsTest extends TestCase
}
}
class
DummyGatewayNotImplementsGatewayInterface
{
}
class
DummyGatewayForTest
implements
GatewayInterface
{
public
function
getName
()
...
...
tests/Traits/HasHttpRequestTest.php
浏览文件 @
639d1cdf
...
...
@@ -13,8 +13,8 @@ namespace Overtrue\EasySms\Tests\Traits;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Psr7\Response
;
use
Overtrue\EasySms\Traits\HasHttpRequest
;
use
Overtrue\EasySms\Tests\TestCase
;
use
Overtrue\EasySms\Traits\HasHttpRequest
;
use
Psr\Http\Message\ResponseInterface
;
class
HasHttpRequestTest
extends
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录