feat : login first

This commit is contained in:
2025-09-26 17:59:26 +08:00
parent 5890122a37
commit 7d09a6028a
7 changed files with 236 additions and 0 deletions

View 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('类不存在')
};
}
}