mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Lib\Jwt;
|
|
|
|
use App\Common\Interface\JwtInterface;
|
|
use Hyperf\Collection\Arr;
|
|
use Hyperf\Contract\ConfigInterface;
|
|
use function Hyperf\Support\make;
|
|
|
|
final class JwtFactory
|
|
{
|
|
public function __construct(
|
|
private readonly ConfigInterface $config,
|
|
) {}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return JwtInterface
|
|
*/
|
|
public function get(string $name = 'default'): JwtInterface
|
|
{
|
|
return make(Jwt::class, [
|
|
'config' => $this->getConfig($name),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 获取场景配置
|
|
* @param string $scene
|
|
* @return array
|
|
*/
|
|
public function getConfig(string $scene): array
|
|
{
|
|
if ($scene === 'default') {
|
|
return $this->config->get($this->getConfigKey());
|
|
}
|
|
return Arr::merge(
|
|
$this->config->get($this->getConfigKey()),
|
|
$this->config->get($this->getConfigKey($scene), [])
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return string
|
|
*/
|
|
private function getConfigKey(string $name = 'default'): string
|
|
{
|
|
return 'jwt.' . $name;
|
|
}
|
|
} |