Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
refs: #70
  • Loading branch information
phper666 committed Feb 2, 2024
1 parent a6dc955 commit abbb142
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
33 changes: 22 additions & 11 deletions src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@

namespace Phper666\JWTAuth;

use Hyperf\Context\ApplicationContext;

function hyperf_make(string $name, array $parameters = [])
{
if (ApplicationContext::hasContainer()) {
/** @var \Hyperf\Di\Container $container */
$container = ApplicationContext::getContainer();
if (method_exists($container, 'make')) {
return $container->make($name, $parameters);
if (!function_exists('make')) {
function make(string $name, array $parameters = [])
{
if (class_exists('\Hyperf\Context\ApplicationContext')) {
if (\Hyperf\Context\ApplicationContext::hasContainer()) {
/** @var \Hyperf\Di\Container $container */
$container = \Hyperf\Context\ApplicationContext::getContainer();
if (method_exists($container, 'make')) {
return $container->make($name, $parameters);
}
}
} elseif (class_exists('\Hyperf\Utils\ApplicationContext')) {
if (\Hyperf\Utils\ApplicationContext::hasContainer()) {
/** @var \Hyperf\Di\Container $container */
$container = \Hyperf\Utils\ApplicationContext::getContainer();
if (method_exists($container, 'make')) {
return $container->make($name, $parameters);
}
}
}

$parameters = array_values($parameters);
return new $name(...$parameters);
}
$parameters = array_values($parameters);
return new $name(...$parameters);
}
8 changes: 4 additions & 4 deletions src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class JWT extends AbstractJWT

public function __construct()
{
$config = hyperf_make(ConfigInterface::class);
$config = make(ConfigInterface::class);
$jwtConfig = $config->get(JWTConstant::CONFIG_NAME, []);
$scenes = $jwtConfig['scene'];
foreach ($scenes as $key => $scene) {
Expand All @@ -98,9 +98,9 @@ public function __construct()
}

$this->jwtConfig = $config->get(JWTConstant::CONFIG_NAME, []);
$this->cache = hyperf_make(CacheInterface::class);
$this->request = hyperf_make(RequestInterface::class);
$this->pathMatch = hyperf_make(PathMatch::class);
$this->cache = make(CacheInterface::class);
$this->request = make(RequestInterface::class);
$this->pathMatch = make(PathMatch::class);
}

/**
Expand Down

0 comments on commit abbb142

Please sign in to comment.