Initial commit

This commit is contained in:
root
2026-01-04 22:05:37 -05:00
committed by Sebastian Krupinski
commit 4f979ced22
57 changed files with 11076 additions and 0 deletions

View 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;
}
}