Passed
Push — master ( 14e18f...4d6973 )
by Dong
01:45
created

Notify::setRedisConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 3
c 1
b 1
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Dongdavid\Notify;
4
5
class Notify
6
{
7
    protected static $types = [
8
        'email' => 'Email',
9
        'wechatoffical' => 'WechatOffical',
10
        'wechatwork' => 'WechatWork',
11
        'miniprogram' => 'MiniProgram',
12
    ];
13
14
    private static function buildConnector($type)
15
    {
16
        $type = strtolower($type);
17
        if (!isset(self::$types[$type])) {
18
            throw new \Exception('错误的通知类型:'.$type);
19
        }
20
21
        $class = false !== strpos($type, '\\') ? $type : '\\Dongdavid\\Notify\\sender\\'.self::$types[$type];
22
23
        return new $class();
24
    }
25
26
    public static function send($data)
27
    {
28
        return self::buildConnector($data['type'])
29
                    ->setConfig($data['config'])
30
                    ->send($data['msg']);
31
    }
32
33
    public static function name($type)
34
    {
35
        return self::buildConnector($type);
36
    }
37
38
}