-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathSend.php
More file actions
60 lines (51 loc) · 1.36 KB
/
Copy pathSend.php
File metadata and controls
60 lines (51 loc) · 1.36 KB
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
<?php
/**
* 消息发送类
*/
namespace framework\ext;
class Send {
/**
* 存储配置
* @var array
*/
protected $config =array(
'driver' => 'Email',
'driverConfig' => array(),
);
/**
* 驱动
* @var string
*/
protected $driver;
/**
* 驱动对象
* @var array
*/
protected static $objArr = array();
/**
* 构建函数
* @param array $config 驱动配置
*/
public function __construct($config) {
$this->config = $config;
if( empty($this->config) || !isset($this->config['driver']) ) {
throw new \Exception('send config error', 500);
}
}
/**
* 回调驱动
* @param string $method 回调方法
* @param array $args 回调参数
* @return object
*/
public function __call($method, $args){
if( !isset(self::$objArr[$this->send]) ){
$sendDriver = __NAMESPACE__.'\send\\' . ucfirst( $this->config['driver'] ).'Driver';
if( !class_exists($sendDriver) ) {
throw new \Exception("Send Driver '{$sendDriver}' not found'", 500);
}
self::$objArr[$this->send] = new $sendDriver( $this->config['driverConfig'] );
}
return call_user_func_array(array(self::$objArr[$this->send], $method), $args);
}
}