anerg2046 /
sns_auth
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * 第三方登陆实例抽象类 |
||
| 5 | * |
||
| 6 | * @author Coeus <[email protected]> |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace anerg\OAuth2; |
||
| 10 | |||
| 11 | use anerg\OAuth2\Connector\GatewayInterface; |
||
| 12 | use anerg\OAuth2\Helper\Str; |
||
| 13 | |||
| 14 | abstract class OAuth |
||
| 15 | { |
||
| 16 | |||
| 17 | protected static function init($gateway, $config = null) |
||
| 18 | { |
||
| 19 | $gateway = Str::uFirst($gateway); |
||
| 20 | $class = __NAMESPACE__ . '\\Gateways\\' . $gateway; |
||
| 21 | if (class_exists($class)) { |
||
| 22 | $app = new $class($config); |
||
| 23 | if ($app instanceof GatewayInterface) { |
||
| 24 | return $app; |
||
| 25 | } |
||
| 26 | throw new \Exception("第三方登录基类 [$gateway] 必须继承抽象类 [GatewayInterface]"); |
||
| 27 | } |
||
| 28 | throw new \Exception("第三方登录基类 [$gateway] 不存在"); |
||
| 29 | } |
||
| 30 | |||
| 31 | public static function __callStatic($gateway, $config) |
||
| 32 | { |
||
| 33 | return self::init($gateway, ...$config); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 34 | } |
||
| 35 | |||
| 36 | } |
||
| 37 |