-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSms.php
86 lines (81 loc) · 2.49 KB
/
Sms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
*
* Класс для отправки смс сообщений
* поддерживает разные транспорты
* @author nur
*
* evil.sms.transport ="Evil_Sms_Sms24x7"
evil.sms.config.email = "[email protected]"
evil.sms.config.password = "8ZvKkD5"
evil.sms.config.sender_name = "opencity.ru"
* $config = array('transport);
*/
class Evil_Sms implements Evil_TransportInterface
{
/**
*
* траспорт который будет использоваться для отправки смс
* @var string
*/
protected $_transport = 'Evil_Sms_Sms24x7';
/**
*
* настройки траспорта
* @var array
*/
protected $_config = array();
protected $_transportInstance = null;
/**
*
* Отправка сообщения
* @param string $to номер телефона, в международном формате
* @example 7902xxxxxxx
* @param string $message
* @return bool
* @throws Zend_Exception
*/
public function send ($to, $message)
{
/**
* ели телефон верный
*/
if($this->_validate($to))
{
/**
* отправка сообщения через транспорт
*/
return $this->_transportInstance->send($to, $message);
}
}
/**
* инициализация транспорта класса
* @var $config array
* $config = array(
* 'transport' => [string],
* 'config' = [array]
* )
*/
public function init (array $config)
{
$this->_config = isset($config['transportconfig']) ? $config['transportconfig'] : array();
$this->_transport = isset($config['transport']) ? $config['transport'] : $this->_transport;
$this->_transportInstance = new $this->_transport();
if ($this->_transportInstance instanceof Evil_Sms_Interface) {
$this->_transportInstance->init($this->_config);
}else {
throw new Zend_Exception(
$this->_transport . ' not instace of Evil_Sms_Interface');
}
}
/* валидация номера телефона
* @param string $phoneNumber
* @return bool
*/
private function _validate ($phoneNumber)
{
$pattern = '/^([0-9]+)([0-9]+)$/';
$vlidator = new Zend_Validate_Regex($pattern);
return $vlidator->isValid($phoneNumber);
}
}