recator: use unified interaface type
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
+52
-21
@@ -18,6 +18,8 @@ use KTXF\Chrono\Service\ServiceEntityMutableInterface;
|
|||||||
use KTXF\Chrono\Entity\EntityBaseInterface;
|
use KTXF\Chrono\Entity\EntityBaseInterface;
|
||||||
use KTXF\Chrono\Entity\EntityMutableInterface;
|
use KTXF\Chrono\Entity\EntityMutableInterface;
|
||||||
use KTXF\Resource\Filter\IFilter;
|
use KTXF\Resource\Filter\IFilter;
|
||||||
|
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||||
|
use KTXF\Resource\Identifier\EntityIdentifier;
|
||||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||||
use KTXF\Resource\Range\RangeAnchorType;
|
use KTXF\Resource\Range\RangeAnchorType;
|
||||||
@@ -514,9 +516,14 @@ class Manager {
|
|||||||
} else {
|
} else {
|
||||||
$collection = $object;
|
$collection = $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// construct parent collection identifier (null for root)
|
||||||
|
$target = $collectionId !== null
|
||||||
|
? new CollectionIdentifier($providerId, (string) $serviceId, (string) $collectionId)
|
||||||
|
: null;
|
||||||
|
|
||||||
// Create collection
|
// Create collection
|
||||||
return $service->collectionCreate($collectionId, $collection, $options);
|
return $service->collectionCreate($target, $collection->getProperties(), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -550,9 +557,12 @@ class Manager {
|
|||||||
} else {
|
} else {
|
||||||
$collection = $object;
|
$collection = $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// construct target collection identifier
|
||||||
|
$target = new CollectionIdentifier($providerId, (string) $serviceId, (string) $collectionId);
|
||||||
|
|
||||||
// Update collection
|
// Update collection
|
||||||
return $service->collectionUpdate($collectionId, $collection);
|
return $service->collectionUpdate($target, $collection->getProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -581,10 +591,14 @@ class Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$force = $options['force'] ?? false;
|
$force = $options['force'] ?? false;
|
||||||
$recursive = $options['recursive'] ?? false;
|
|
||||||
|
|
||||||
// delete collection
|
// construct target collection identifier
|
||||||
return $service->collectionDelete($collectionId, $force, $recursive);
|
$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 ====================
|
// ==================== Entity Operations ====================
|
||||||
@@ -663,7 +677,7 @@ class Manager {
|
|||||||
}
|
}
|
||||||
// retrieve entities for each collection
|
// retrieve entities for each collection
|
||||||
foreach ($collectionSelected as $collectionId) {
|
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
|
// skip collections with no entities
|
||||||
if ($entities === []) {
|
if ($entities === []) {
|
||||||
continue;
|
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 {
|
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);
|
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
|
||||||
|
|
||||||
// retrieve collection
|
// construct entity identifiers
|
||||||
return $service->entityFetch($collectionId, ...$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 {
|
} else {
|
||||||
$entity = $object;
|
$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)) {
|
if (!($service instanceof ServiceEntityMutableInterface)) {
|
||||||
throw new InvalidArgumentException("Service does not support entity mutations");
|
throw new InvalidArgumentException("Service does not support entity mutations");
|
||||||
}
|
}
|
||||||
if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_CREATE)) {
|
if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_MODIFY)) {
|
||||||
throw new InvalidArgumentException("Service is not capable of creating entities");
|
throw new InvalidArgumentException("Service is not capable of modifying entities");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($object)) {
|
if (is_array($object)) {
|
||||||
@@ -888,8 +911,11 @@ class Manager {
|
|||||||
} else {
|
} else {
|
||||||
$entity = $object;
|
$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)) {
|
if (!($service instanceof ServiceEntityMutableInterface)) {
|
||||||
throw new InvalidArgumentException('Service does not support entity destruction');
|
throw new InvalidArgumentException('Service does not support entity destruction');
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity = $service->entityDelete($collectionId, $identifier);
|
// construct target entity identifier
|
||||||
|
$target = new EntityIdentifier($providerId, (string) $serviceId, (string) $collectionId, (string) $identifier);
|
||||||
return $entity !== null;
|
|
||||||
|
// delete entity (returns results keyed by source identifier)
|
||||||
|
$results = $service->entityDelete($target);
|
||||||
|
$outcome = $results[(string) $target] ?? null;
|
||||||
|
|
||||||
|
return $outcome !== null && ($outcome['disposition'] ?? 'error') !== 'error';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user