From 557f42a06c775a2355e2ab2ab6803257ff415157 Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Thu, 25 Jun 2026 23:36:13 -0400 Subject: [PATCH] recator: use unified interaface type Signed-off-by: Sebastian Krupinski --- lib/Manager.php | 73 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/lib/Manager.php b/lib/Manager.php index e5ae138..03a537c 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -18,6 +18,8 @@ use KTXF\Chrono\Service\ServiceEntityMutableInterface; use KTXF\Chrono\Entity\EntityBaseInterface; use KTXF\Chrono\Entity\EntityMutableInterface; use KTXF\Resource\Filter\IFilter; +use KTXF\Resource\Identifier\CollectionIdentifier; +use KTXF\Resource\Identifier\EntityIdentifier; use KTXF\Resource\Provider\ResourceServiceIdentityInterface; use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Resource\Range\RangeAnchorType; @@ -514,9 +516,14 @@ class Manager { } else { $collection = $object; } - + + // construct parent collection identifier (null for root) + $target = $collectionId !== null + ? new CollectionIdentifier($providerId, (string) $serviceId, (string) $collectionId) + : null; + // Create collection - return $service->collectionCreate($collectionId, $collection, $options); + return $service->collectionCreate($target, $collection->getProperties(), $options); } /** @@ -550,9 +557,12 @@ class Manager { } else { $collection = $object; } - + + // construct target collection identifier + $target = new CollectionIdentifier($providerId, (string) $serviceId, (string) $collectionId); + // Update collection - return $service->collectionUpdate($collectionId, $collection); + return $service->collectionUpdate($target, $collection->getProperties()); } /** @@ -581,10 +591,14 @@ class Manager { } $force = $options['force'] ?? false; - $recursive = $options['recursive'] ?? false; - // delete collection - return $service->collectionDelete($collectionId, $force, $recursive); + // construct target collection identifier + $target = new CollectionIdentifier($providerId, (string) $serviceId, (string) $collectionId); + + // delete collection (service returns the collection object on soft delete, true on hard delete) + $result = $service->collectionDelete($target, $force); + + return $result === true || $result instanceof CollectionBaseInterface; } // ==================== Entity Operations ==================== @@ -663,7 +677,7 @@ class Manager { } // retrieve entities for each collection foreach ($collectionSelected as $collectionId) { - $entities = $service->entityList($collectionId, $entityFilter, $entitySort, $entityRange, null); + $entities = $service->entityListBulk($collectionId, $entityFilter, $entitySort, $entityRange, null); // skip collections with no entities if ($entities === []) { continue; @@ -692,9 +706,15 @@ class Manager { */ public function entityFetch(string $tenantId, ?string $userId, string $providerId, string|int $serviceId, string|int $collectionId, array $identifiers): array { $service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId); - - // retrieve collection - return $service->entityFetch($collectionId, ...$identifiers); + + // construct entity identifiers + $targets = array_map( + fn($identifier) => new EntityIdentifier($providerId, (string) $serviceId, (string) $collectionId, (string) $identifier), + $identifiers + ); + + // retrieve entities + return $service->entityFetchBulk(...$targets); } /** @@ -852,8 +872,11 @@ class Manager { } else { $entity = $object; } - - return $service->entityCreate($collectionId, $entity, $options); + + // construct target collection identifier + $target = new CollectionIdentifier($providerId, (string) $serviceId, (string) $collectionId); + + return $service->entityCreate($target, $entity->getProperties(), $options); } /** @@ -878,8 +901,8 @@ class Manager { if (!($service instanceof ServiceEntityMutableInterface)) { throw new InvalidArgumentException("Service does not support entity mutations"); } - if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_CREATE)) { - throw new InvalidArgumentException("Service is not capable of creating entities"); + if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_MODIFY)) { + throw new InvalidArgumentException("Service is not capable of modifying entities"); } if (is_array($object)) { @@ -888,8 +911,11 @@ class Manager { } else { $entity = $object; } - - return $service->entityUpdate($collectionId, $identifier, $entity); + + // construct target entity identifier + $target = new EntityIdentifier($providerId, (string) $serviceId, (string) $collectionId, (string) $identifier); + + return $service->entityModify($target, $entity->getProperties()); } /** @@ -911,10 +937,15 @@ class Manager { if (!($service instanceof ServiceEntityMutableInterface)) { throw new InvalidArgumentException('Service does not support entity destruction'); } - - $entity = $service->entityDelete($collectionId, $identifier); - - return $entity !== null; + + // construct target entity identifier + $target = new EntityIdentifier($providerId, (string) $serviceId, (string) $collectionId, (string) $identifier); + + // delete entity (returns results keyed by source identifier) + $results = $service->entityDelete($target); + $outcome = $results[(string) $target] ?? null; + + return $outcome !== null && ($outcome['disposition'] ?? 'error') !== 'error'; } }