123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace traits\think;
- use think\Exception;
- trait Instance
- {
-
- protected static $instance = null;
-
- public static function instance($options = [])
- {
- if (is_null(self::$instance)) self::$instance = new self($options);
- return self::$instance;
- }
-
- public static function __callStatic($method, array $params)
- {
- if (is_null(self::$instance)) self::$instance = new self();
- $call = substr($method, 1);
- if (0 !== strpos($method, '_') || !is_callable([self::$instance, $call])) {
- throw new Exception("method not exists:" . $method);
- }
- return call_user_func_array([self::$instance, $call], $params);
- }
- }
|