1 | <?php |
||
2 | /** |
||
3 | * SpreadSheet |
||
4 | * @author: JiaMeng <[email protected]> |
||
5 | */ |
||
6 | namespace tinymeng\spreadsheet; |
||
7 | |||
8 | // 目录入口 |
||
9 | define('SPREADSHEET_ROOT_PATH', dirname(__DIR__)); |
||
10 | |||
11 | use tinymeng\spreadsheet\Gateways\Export; |
||
12 | use tinymeng\spreadsheet\Gateways\Import; |
||
13 | use tinymeng\tools\StringTool; |
||
14 | use tinymeng\spreadsheet\Connector\GatewayInterface; |
||
15 | /** |
||
16 | * @method static Export export(array|null $config) 导出 |
||
17 | * @method static Import import(array|null $config) 导入 |
||
18 | */ |
||
19 | abstract class TSpreadSheet |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Description: init |
||
24 | * @author: JiaMeng <[email protected]> |
||
25 | * Updater: |
||
26 | * @param $gateway |
||
27 | * @param null $config |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
28 | * @return mixed |
||
29 | * @throws \Exception |
||
30 | */ |
||
31 | protected static function init($gateway, $config=[]) |
||
32 | { |
||
33 | $gateway = StringTool::uFirst($gateway); |
||
34 | $class = __NAMESPACE__ . '\\Gateways\\' . $gateway; |
||
35 | if (class_exists($class)) { |
||
36 | $configFile = SPREADSHEET_ROOT_PATH."/config/TSpreadSheet.php"; |
||
37 | if (!file_exists($configFile)) { |
||
38 | return false; |
||
39 | } |
||
40 | $baseConfig = require $configFile; |
||
41 | $app = new $class(array_replace_recursive($baseConfig,$config)); |
||
42 | if ($app instanceof GatewayInterface) { |
||
43 | return $app; |
||
44 | } |
||
45 | throw new \Exception("基类 [$gateway] 必须继承抽象类 [GatewayInterface]"); |
||
46 | } |
||
47 | throw new \Exception("基类 [$gateway] 不存在"); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Description: __callStatic |
||
52 | * @author: JiaMeng <[email protected]> |
||
53 | * Updater: |
||
54 | * @param $gateway |
||
55 | * @param $config |
||
56 | * @return mixed |
||
57 | */ |
||
58 | public static function __callStatic($gateway, $config=[]) |
||
59 | { |
||
60 | return self::init($gateway, ...$config); |
||
61 | } |
||
62 | |||
63 | } |
||
64 |