mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Api\Login;
|
|
|
|
use App\Exception\ErrException;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\ContainerInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class LoginFactory
|
|
{
|
|
/**
|
|
* 策略映射 对应 request type
|
|
*/
|
|
private const array HANDLER_MAP = [
|
|
'password' => PasswordLoginService::class
|
|
];
|
|
|
|
/**
|
|
* @param ContainerInterface $container
|
|
*/
|
|
public function __construct(
|
|
private readonly ContainerInterface $container
|
|
) {}
|
|
|
|
/**
|
|
* @param string $type
|
|
* @return PasswordLoginService
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function get(string $type):
|
|
PasswordLoginService
|
|
{
|
|
$handlerClass = self::HANDLER_MAP[$type] ?? null;
|
|
|
|
return match (true) {
|
|
$handlerClass !== null => $this->container->get($handlerClass),
|
|
default => throw new ErrException('类不存在')
|
|
};
|
|
}
|
|
} |