-
Notifications
You must be signed in to change notification settings - Fork 20
/
PosterManager.php
77 lines (66 loc) · 2.18 KB
/
PosterManager.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
<?php
namespace Kkokk\Poster;
/**
* PHP海报生成,添加水印
* @Author: lang
* @Email: [email protected]
* @Date: 2020-08-14 10:38:17
* @Last Modified by: lang
* @Last Modified time: 2021-09-08 10:23:08
*/
use Kkokk\Poster\Exception\SystemException;
class PosterManager
{
protected static $options; // 参数
protected static $connector; // 实例化类
protected static $className; // 实现调用类名
public function __construct($options = [])
{
if (!empty($options)) {
self::$options = !is_array($options) ? [$options] : $options;
}
}
public function __call($method, $params)
{
$lang = new self();
// self::$className = __NAMESPACE__ . '\\Lang\\AbstractTest'; // 使用抽象类实现
self::$className = __NAMESPACE__ . '\\Lang\\Poster';
return $lang->create($method, $params);
}
/**
* @param $method
* @param $params
* @return mixed
* @throws SystemException
*/
public static function __callStatic($method, $params)
{
self::$options = $params;
self::$className = __NAMESPACE__ . '\\Lang\\' . $method; // 使用接口类实现 只是测试不同方式实现
return self::buildConnector();
}
/**
* @param string $method
* @param array $params
* @return mixed
* @throws SystemException
*/
private function create($method, $params)
{
return call_user_func_array([self::buildConnector(), $method], $params);
}
private static function buildConnector()
{
if (!isset(self::$connector[self::$className])) {
if (!class_exists(self::$className)) {
throw new SystemException("the class name does not exist . class : " . self::$className);
}
if (empty(self::$options)) {
self::$connector[self::$className] = new self::$className(self::$options);
} else {
self::$connector[self::$className] = new self::$className(...self::$options);
}
}
return self::$connector[self::$className];
}
}