全栈小学生 333877eca2 update
2024-08-06 17:48:00 +08:00

77 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Kkokk\Poster;
/**
* PHP海报生成添加水印
* @Author: lang
* @Email: 732853989@qq.com
* @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];
}
}