mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
feat : login first
This commit is contained in:
50
app/Service/Api/Login/LoginFactory.php
Normal file
50
app/Service/Api/Login/LoginFactory.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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('类不存在')
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user