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]; } }