PosterManager.php
1.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Author: lang
* Email: 732853989@qq.com
* Date: 2023/3/22
* Time: 13:43
*/
namespace Kkokk\Poster\Image;
class PosterManager
{
protected $extensions = [];
protected $factory;
protected $path;
function __construct($path = null) // 兼容老版本设置路径
{
$this->path = $path;
$this->factory = new ExtensionFactory;
}
public function extension($name = null)
{
$name = $this->parseConnectionName($name);
if (!isset($this->extensions[$name])) {
$this->extensions[$name] = $this->configure($this->makeExtension($name));
}
return $this->extensions[$name];
}
protected function configure(Extension $extension)
{
return $extension;
}
protected function parseConnectionName($name)
{
if (empty($name)) return $this->supportedExtensions()[0];
return $name;
}
/**
* 创建一个拓展实例
* Author: lang
* Email: 732853989@qq.com
* Date: 2023/3/22
* Time: 13:58
* @param $name
*/
protected function makeExtension($name)
{
return $this->factory->make($name, $this->path);
}
/**
* 获取所有支持拓展。
*
* @return array
*/
public function supportedExtensions()
{
return ['gd', 'imagick'];
}
/**
* 将方法动态传递给默认拓展。
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->extension()->$method(...$parameters);
}
}