Initial commit
This commit is contained in:
134
lib/Providers/Chrono/Provider.php
Normal file
134
lib/Providers/Chrono/Provider.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderJmapc\Providers\Chrono;
|
||||
|
||||
use KTXF\Chrono\Provider\IProviderBase;
|
||||
use KTXF\Chrono\Provider\IProviderServiceMutate;
|
||||
use KTXF\Chrono\Service\IServiceBase;
|
||||
use KTXF\Chrono\Service\ServiceScope;
|
||||
use KTXM\ProviderJmapc\Stores\ServiceStore;
|
||||
|
||||
/**
|
||||
* JMAP Chrono Provider
|
||||
*
|
||||
* Provides Calendar services via JMAP protocol.
|
||||
* Filters services by urn:ietf:params:jmap:calendars capability.
|
||||
*/
|
||||
class Provider implements IProviderBase, IProviderServiceMutate
|
||||
{
|
||||
protected const CALENDAR_CAPABILITY = 'urn:ietf:params:jmap:calendars';
|
||||
|
||||
public function __construct(
|
||||
protected readonly ServiceStore $serviceStore,
|
||||
) {}
|
||||
|
||||
public function capable(string $value): bool
|
||||
{
|
||||
$capabilities = [
|
||||
self::CAPABILITY_SERVICE_LIST,
|
||||
self::CAPABILITY_SERVICE_FETCH,
|
||||
self::CAPABILITY_SERVICE_EXTANT,
|
||||
self::CAPABILITY_SERVICE_FRESH,
|
||||
self::CAPABILITY_SERVICE_CREATE,
|
||||
self::CAPABILITY_SERVICE_MODIFY,
|
||||
self::CAPABILITY_SERVICE_DESTROY,
|
||||
];
|
||||
return in_array($value, $capabilities, true);
|
||||
}
|
||||
|
||||
public function capabilities(): array
|
||||
{
|
||||
return [
|
||||
self::CAPABILITY_SERVICE_LIST => true,
|
||||
self::CAPABILITY_SERVICE_FETCH => true,
|
||||
self::CAPABILITY_SERVICE_EXTANT => true,
|
||||
self::CAPABILITY_SERVICE_FRESH => true,
|
||||
self::CAPABILITY_SERVICE_CREATE => true,
|
||||
self::CAPABILITY_SERVICE_MODIFY => true,
|
||||
self::CAPABILITY_SERVICE_DESTROY => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function id(): string
|
||||
{
|
||||
return 'jmap';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'JMAP Calendar Provider';
|
||||
}
|
||||
|
||||
public function serviceList(string $tenantId, string $userId, array $filter): array
|
||||
{
|
||||
// Filter by Calendar capability
|
||||
return $this->serviceStore->listServices($tenantId, $userId, [self::CALENDAR_CAPABILITY]);
|
||||
}
|
||||
|
||||
public function serviceExtant(string $tenantId, string $userId, array $identifiers): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($identifiers as $id) {
|
||||
$service = $this->serviceStore->getService($tenantId, $userId, $id);
|
||||
$result[$id] = $service !== null;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?IServiceBase
|
||||
{
|
||||
return $this->serviceStore->getService($tenantId, $userId, $identifier);
|
||||
}
|
||||
|
||||
public function serviceFresh(string $userId = ''): IServiceBase
|
||||
{
|
||||
return new Service(
|
||||
scope: ServiceScope::User,
|
||||
enabled: true,
|
||||
);
|
||||
}
|
||||
|
||||
public function serviceCreate(string $userId, IServiceBase $service): string
|
||||
{
|
||||
if (!($service instanceof Service)) {
|
||||
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Use Mail Provider interface for service creation');
|
||||
}
|
||||
|
||||
public function serviceModify(string $userId, IServiceBase $service): string
|
||||
{
|
||||
if (!($service instanceof Service)) {
|
||||
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Use Mail Provider interface for service modification');
|
||||
}
|
||||
|
||||
public function serviceDestroy(string $userId, IServiceBase $service): bool
|
||||
{
|
||||
if (!($service instanceof Service)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Use Mail Provider interface for service destruction');
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'@type' => 'chrono.provider',
|
||||
'id' => $this->id(),
|
||||
'label' => $this->label(),
|
||||
'capabilities' => $this->capabilities(),
|
||||
];
|
||||
}
|
||||
|
||||
public function jsonDeserialize(array|string $data): static
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user