mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 07:15:06 +08:00
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Singularity\HDK\Core\Service;
|
|
|
|
use Hyperf\Context\Context;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
/**
|
|
* 资源扩展
|
|
*/
|
|
class ExtendService
|
|
{
|
|
public function __construct(private UtilsService $utils)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param ServerRequestInterface|null $request
|
|
* @param array<string, string>|null $params
|
|
* @return string[]
|
|
*/
|
|
public function parse(
|
|
?ServerRequestInterface $request,
|
|
array|string|null $params = null
|
|
): array {
|
|
$params ??= $request?->getQueryParams();
|
|
$extends = explode(',', $params['extends'] ?? '');
|
|
$extends = array_map('trim', $extends);
|
|
|
|
return Context::set(self::class, array_filter($extends));
|
|
}
|
|
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function getExtends(): array
|
|
{
|
|
return Context::get(self::class) ?? [];
|
|
}
|
|
|
|
public function hasExtends(): bool
|
|
{
|
|
$extends = Context::get(self::class);
|
|
return is_array($extends) && count($extends) > 0;
|
|
}
|
|
|
|
/**
|
|
* 判断是否传入了此扩展
|
|
*
|
|
* @param string $field
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasExtend(string $field): bool
|
|
{
|
|
return $this->utils->inArray($field, Context::get(self::class) ?? []);
|
|
}
|
|
}
|