feat: add local system store provider
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderLocalDocuments\Providers\SystemStore;
|
||||
|
||||
use DI\Attribute\Inject;
|
||||
use KTXF\Resource\Provider\ResourceServiceBaseInterface;
|
||||
use KTXF\Resource\SystemIdentity;
|
||||
use KTXF\SystemStore\Provider\ProviderBaseInterface;
|
||||
|
||||
final class Provider implements ProviderBaseInterface
|
||||
{
|
||||
public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE;
|
||||
public const PROVIDER_IDENTIFIER = 'local';
|
||||
private const SERVICE_IDENTIFIER = 'default';
|
||||
|
||||
private array $providerAbilities = [
|
||||
self::CAPABILITY_SERVICE_LIST => true,
|
||||
self::CAPABILITY_SERVICE_FETCH => true,
|
||||
self::CAPABILITY_SERVICE_EXTANT => true,
|
||||
];
|
||||
|
||||
public function __construct(#[Inject('rootDir')] private readonly string $rootDir)
|
||||
{
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
self::PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
||||
self::PROPERTY_LABEL => $this->label(),
|
||||
self::PROPERTY_CAPABILITIES => $this->providerAbilities,
|
||||
];
|
||||
}
|
||||
|
||||
public function jsonDeserialize(array|string $data): static { return $this; }
|
||||
public function type(): string { return self::TYPE_SYSTEM_STORE; }
|
||||
public function identifier(): string { return self::PROVIDER_IDENTIFIER; }
|
||||
public function label(): string { return 'Local System Store'; }
|
||||
public function description(): string { return 'Stores tenant-owned internal blobs on local disk'; }
|
||||
public function icon(): string { return 'hard-drive'; }
|
||||
public function capable(string $value): bool { return !empty($this->providerAbilities[$value]); }
|
||||
public function capabilities(): array { return $this->providerAbilities; }
|
||||
|
||||
public function serviceList(string $tenantId, string $userId, array $filter): array
|
||||
{
|
||||
if ($userId !== SystemIdentity::USER || ($filter !== [] && !in_array(self::SERVICE_IDENTIFIER, $filter, true))) {
|
||||
return [];
|
||||
}
|
||||
return [self::SERVICE_IDENTIFIER => $this->service($tenantId)];
|
||||
}
|
||||
|
||||
public function serviceExtant(string $tenantId, string $userId, int|string ...$identifiers): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
$result[$identifier] = $userId === SystemIdentity::USER && $identifier === self::SERVICE_IDENTIFIER;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?ResourceServiceBaseInterface
|
||||
{
|
||||
if ($userId !== SystemIdentity::USER || $identifier !== self::SERVICE_IDENTIFIER) {
|
||||
return null;
|
||||
}
|
||||
return $this->service($tenantId);
|
||||
}
|
||||
|
||||
private function service(string $tenantId): Service
|
||||
{
|
||||
return new Service($this->rootDir . '/storage/system-store/' . hash('sha256', $tenantId) . '/default');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user