132 lines
3.4 KiB
PHP
132 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXM\ProviderLocalDocuments\Providers;
|
|
|
|
use DI\Attribute\Inject;
|
|
use Psr\Container\ContainerInterface;
|
|
use KTXF\Resource\Documents\Provider\ProviderBaseInterface;
|
|
use KTXF\Resource\Documents\Service\ServiceBaseInterface;
|
|
use KTXM\ProviderLocalDocuments\Module;
|
|
use KTXM\ProviderLocalDocuments\Providers\Personal\PersonalService;
|
|
|
|
class Provider implements ProviderBaseInterface {
|
|
|
|
public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE;
|
|
public const PROVIDER_IDENTIFIER = 'default';
|
|
protected const PROVIDER_LABEL = Module::MODULE_LABEL;
|
|
protected const PROVIDER_DESCRIPTION = Module::MODULE_DESCRIPTION;
|
|
protected const PROVIDER_ICON = 'folder';
|
|
|
|
protected string $storeLocation = '/tmp/ktrix';
|
|
|
|
protected array $providerAbilities = [
|
|
self::CAPABILITY_SERVICE_LIST => true,
|
|
self::CAPABILITY_SERVICE_FETCH => true,
|
|
self::CAPABILITY_SERVICE_EXTANT => true,
|
|
];
|
|
public function __construct(
|
|
private readonly ContainerInterface $container,
|
|
#[Inject('rootDir')] private readonly string $rootDir,
|
|
) {
|
|
$this->storeLocation = $this->rootDir . '/storage/';
|
|
}
|
|
|
|
public function jsonSerialize(): array
|
|
{
|
|
return [
|
|
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
|
self::JSON_PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
|
self::JSON_PROPERTY_LABEL => self::PROVIDER_LABEL,
|
|
self::JSON_PROPERTY_CAPABILITIES => $this->providerAbilities,
|
|
];
|
|
}
|
|
|
|
public function jsonDeserialize(array|string $data): static
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function type(): string
|
|
{
|
|
return self::TYPE_CHRONO;
|
|
}
|
|
|
|
public function identifier(): string
|
|
{
|
|
return self::PROVIDER_IDENTIFIER;
|
|
}
|
|
|
|
public function label(): string
|
|
{
|
|
return self::PROVIDER_LABEL;
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return self::PROVIDER_DESCRIPTION;
|
|
}
|
|
|
|
public function icon(): string
|
|
{
|
|
return self::PROVIDER_ICON;
|
|
}
|
|
|
|
public function capable(string $value): bool
|
|
{
|
|
return !empty($this->providerAbilities[$value]);
|
|
}
|
|
|
|
public function capabilities(): array
|
|
{
|
|
return $this->providerAbilities;
|
|
}
|
|
|
|
protected function serviceInstancePersonal(string $tenantId, string $userId): PersonalService {
|
|
$service = $this->container->get(PersonalService::class);
|
|
$service->initialize($tenantId, $userId, $this->storeLocation . "$tenantId/$userId");
|
|
return $service;
|
|
}
|
|
|
|
public function serviceList(string $tenantId, string $userId, array $filter = []): array {
|
|
// if no filter is provided, return all services
|
|
if ($filter === []) {
|
|
$filter = ['personal'];
|
|
}
|
|
// build services list
|
|
$services = [];
|
|
if (in_array('personal', $filter, true)) {
|
|
$services['personal'] = $this->serviceInstancePersonal($tenantId, $userId);
|
|
}
|
|
return $services;
|
|
}
|
|
|
|
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?ServiceBaseInterface {
|
|
|
|
if ($identifier === 'personal') {
|
|
return $this->serviceInstancePersonal($tenantId, $userId);
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
public function serviceExtant(string $tenantId, string $userId, int|string ...$identifiers): array {
|
|
$data = [];
|
|
foreach ($identifiers as $id) {
|
|
$data[$id] = match ($id) {
|
|
'personal' => true,
|
|
default => false,
|
|
};
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
}
|