Facade.php
1.4 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
<?php
/**
* Author: lang
* Email: 732853989@qq.com
* Date: 2022/12/15
* Time: 14:21
*/
namespace Kkokk\Poster\Facades;
use Kkokk\Poster\Exception\PosterException;
abstract class Facade
{
protected static $resolvedInstance = [];
protected static $store = [
'cache' => \Kkokk\Poster\Cache\Repository::class,
'poster' => \Kkokk\Poster\Image\PosterManager::class,
'captcha' => \Kkokk\Poster\Lang\Captcha::class,
];
protected static function getInstance()
{
return static::setInstance(static::getFacadeModel());
}
/**
* Author: lang
* Email: 732853989@qq.com
* Date: 2023/3/10
* Time: 14:14
* @return string
* @throws PosterException
*/
protected static function getFacadeModel()
{
throw new PosterException('未获取到模型');
}
// 设置实例
protected static function setInstance($model)
{
if (is_object($model)) {
return $model;
}
if (!isset($resolvedInstance[$model])) {
// 单例
static::$resolvedInstance = new self::$store[$model];
}
return static::$resolvedInstance;
}
public static function __callStatic($method, $args)
{
$instance = static::getInstance();
if (!$instance) {
throw new PosterException('未找到相关实例与方法');
}
return $instance->$method(...$args);
}
}