Skip to content

Commit d3c09c3

Browse files
committed
Merge branch 'sync'
2 parents 51f37f8 + b9ff761 commit d3c09c3

File tree

5 files changed

+34
-65
lines changed

5 files changed

+34
-65
lines changed

src/Facade/Sync.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
* @method static SyncStore namespace(string $prefix, string $uri, string $namespace, class-string<ISyncClassResolver>|null $resolver = null) Register a sync entity namespace (see {@see SyncStore::namespace()})
4747
* @method static SyncStore provider(ISyncProvider $provider) Register a sync provider and set its provider ID (see {@see SyncStore::provider()})
4848
* @method static SyncStore reportErrors(string $successText = 'No sync errors recorded') Report sync errors recorded so far to the console (see {@see SyncStore::reportErrors()})
49-
* @method static ISyncEntity[]|null resolveDeferred(?int $fromCheckpoint = null, bool $return = false) Resolve deferred sync entities and relationships recursively until no deferrals remain
50-
* @method static ISyncEntity[] resolveDeferredEntities(?int $fromCheckpoint = null, ?int $providerId = null, class-string<ISyncEntity>|null $entityType = null, bool|null $offline = null) Resolve deferred sync entities from their respective providers and/or the local entity store (see {@see SyncStore::resolveDeferredEntities()})
51-
* @method static array<ISyncEntity[]> resolveDeferredRelationships(?int $fromCheckpoint = null, ?int $providerId = null, class-string<ISyncEntity>|null $entityType = null, class-string<ISyncEntity>|null $forEntityType = null, bool|null $offline = null) Resolve deferred relationships from their respective providers and/or the local entity store (see {@see SyncStore::resolveDeferredRelationships()})
49+
* @method static ISyncEntity[]|null resolveDeferred(?int $fromCheckpoint = null, class-string<ISyncEntity>|null $entityType = null, bool $return = false) Resolve deferred sync entities and relationships recursively until no deferrals remain
50+
* @method static ISyncEntity[] resolveDeferredEntities(?int $fromCheckpoint = null, class-string<ISyncEntity>|null $entityType = null, ?int $providerId = null) Resolve deferred sync entities from their respective providers and/or the local entity store
51+
* @method static array<ISyncEntity[]> resolveDeferredRelationships(?int $fromCheckpoint = null, class-string<ISyncEntity>|null $entityType = null, class-string<ISyncEntity>|null $forEntityType = null, ?int $providerId = null) Resolve deferred relationships from their respective providers and/or the local entity store
5252
*
5353
* @uses SyncStore
5454
*

src/Sync/Support/DeferredEntity.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,21 @@ private function typeUri(bool $compact): string
145145
/**
146146
* Resolve the deferred entity from the provider or the local entity store
147147
*
148-
* @param bool|null $offline If `null` (the default), the local entity store
149-
* is used if its copy of the entity is sufficiently fresh, or if the
150-
* provider cannot be reached. If `true`, the local entity store is used
151-
* unconditionally. If `false`, the local entity store is unconditionally
152-
* ignored.
153148
* @return TEntity
154149
*/
155-
public function resolve(?bool $offline = null): ISyncEntity
150+
public function resolve(): ISyncEntity
156151
{
157152
if ($this->Resolved !== null) {
158153
return $this->Resolved;
159154
}
160155

161-
$provider = $this->Provider->with($this->Entity, $this->Context);
156+
$entity =
157+
$this
158+
->Provider
159+
->with($this->Entity, $this->Context)
160+
->get($this->EntityId);
162161

163-
if ($offline === true) {
164-
$provider = $provider->offline();
165-
} elseif ($offline === false) {
166-
$provider = $provider->online();
167-
}
168-
169-
$entity = $provider->get($this->EntityId);
170162
$this->Resolved = $entity;
171-
172163
return $entity;
173164
}
174165

src/Sync/Support/DeferredRelationship.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,38 +148,28 @@ public function getIterator(): Traversable
148148
* Resolve the deferred relationship with entities retrieved from the
149149
* provider or the local entity store
150150
*
151-
* @param bool|null $offline If `null` (the default), the local entity store
152-
* is used if its copy of the entities is sufficiently fresh, or if the
153-
* provider cannot be reached. If `true`, the local entity store is used
154-
* unconditionally. If `false`, the local entity store is unconditionally
155-
* ignored.
156151
* @return TEntity[]
157152
*/
158-
public function resolve(?bool $offline = null): array
153+
public function resolve(): array
159154
{
160155
if ($this->Resolved !== null) {
161156
return $this->Resolved;
162157
}
163158

164-
$provider = $this->Provider->with($this->Entity, $this->Context);
165-
166-
if ($offline === true) {
167-
$provider = $provider->offline();
168-
} elseif ($offline === false) {
169-
$provider = $provider->online();
170-
}
171-
172-
$entities = $provider->getListA(
173-
$this->Filter !== null
174-
? $this->Filter
175-
: [
176-
Convert::classToBasename($this->ForEntity) =>
177-
$this->ForEntityId,
178-
],
179-
);
159+
$entities =
160+
$this
161+
->Provider
162+
->with($this->Entity, $this->Context)
163+
->getListA(
164+
$this->Filter !== null
165+
? $this->Filter
166+
: [
167+
Convert::classToBasename($this->ForEntity) =>
168+
$this->ForEntityId,
169+
],
170+
);
180171

181172
$this->apply($entities);
182-
183173
return $entities;
184174
}
185175

src/Sync/Support/SyncIntrospector.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function (ISyncContext $ctx, ...$args) use ($entity, $operation) {
350350

351351
/**
352352
* @param string[] $keys
353-
* @return Closure(mixed[], string|null, IContainer, ISyncProvider|null, ISyncContext|null, DateFormatter|null, ITreeable|null, bool|null $offline=): TClass
353+
* @return Closure(mixed[], string|null, IContainer, ISyncProvider|null, ISyncContext|null, DateFormatter|null, ITreeable|null): TClass
354354
*/
355355
private function _getCreateFromSignatureSyncClosure(array $keys, bool $strict = false): Closure
356356
{
@@ -382,8 +382,7 @@ private function _getCreateFromSignatureSyncClosure(array $keys, bool $strict =
382382
?ISyncProvider $provider,
383383
?ISyncContext $context,
384384
?DateFormatter $dateFormatter,
385-
?ITreeable $parent,
386-
?bool $offline = null
385+
?ITreeable $parent
387386
) use ($constructor, $updater, $resolver) {
388387
$obj = $constructor($array, $service, $container);
389388
$obj = $updater($array, $obj, $container, $provider, $context, $dateFormatter, $parent);
@@ -402,8 +401,7 @@ private function _getCreateFromSignatureSyncClosure(array $keys, bool $strict =
402401
?ISyncProvider $provider,
403402
?ISyncContext $context,
404403
?DateFormatter $dateFormatter,
405-
?ITreeable $parent,
406-
?bool $offline = null
404+
?ITreeable $parent
407405
) use (
408406
$constructor,
409407
$updater,
@@ -427,7 +425,7 @@ private function _getCreateFromSignatureSyncClosure(array $keys, bool $strict =
427425

428426
$store = $provider->store()->entityType($service ?? $entityType);
429427
$providerId = $provider->getProviderId();
430-
$obj = $store->getEntity($providerId, $service ?? $entityType, $id, $offline);
428+
$obj = $store->getEntity($providerId, $service ?? $entityType, $id, $context->getOffline());
431429

432430
if ($obj) {
433431
$obj = $existingUpdater($array, $obj, $container, $provider, $context, $dateFormatter, $parent);

src/Sync/Support/SyncStore.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -923,18 +923,20 @@ public function deferredRelationship(
923923
* Resolve deferred sync entities and relationships recursively until no
924924
* deferrals remain
925925
*
926+
* @param class-string<ISyncEntity>|null $entityType
926927
* @return ISyncEntity[]|null
927928
*/
928929
public function resolveDeferred(
929930
?int $fromCheckpoint = null,
931+
?string $entityType = null,
930932
bool $return = false
931933
): ?array {
932934
$checkpoint = $this->DeferralCheckpoint;
933935
do {
934936
// Resolve relationships first because they typically deliver
935937
// multiple entities per round trip, some of which may be in the
936938
// deferred entity queue
937-
$deferred = $this->resolveDeferredRelationships($fromCheckpoint);
939+
$deferred = $this->resolveDeferredRelationships($fromCheckpoint, $entityType);
938940
if ($deferred) {
939941
if (!$return) {
940942
continue;
@@ -951,7 +953,7 @@ public function resolveDeferred(
951953
continue;
952954
}
953955

954-
$deferred = $this->resolveDeferredEntities($fromCheckpoint);
956+
$deferred = $this->resolveDeferredEntities($fromCheckpoint, $entityType);
955957
if (!$deferred || !$return) {
956958
continue;
957959
}
@@ -985,18 +987,12 @@ public function getDeferralCheckpoint(): int
985987
* local entity store
986988
*
987989
* @param class-string<ISyncEntity>|null $entityType
988-
* @param bool|null $offline If `null` (the default), the local entity store
989-
* is used if its copy of the entities is sufficiently fresh, or if the
990-
* provider cannot be reached. If `true`, the local entity store is used
991-
* unconditionally. If `false`, the local entity store is unconditionally
992-
* ignored.
993990
* @return ISyncEntity[]
994991
*/
995992
public function resolveDeferredEntities(
996993
?int $fromCheckpoint = null,
997-
?int $providerId = null,
998994
?string $entityType = null,
999-
?bool $offline = null
995+
?int $providerId = null
1000996
): array {
1001997
$entityTypeId = $entityType === null
1002998
? null
@@ -1032,7 +1028,7 @@ public function resolveDeferredEntities(
10321028

10331029
foreach ($entities as $entityId => $deferred) {
10341030
$deferredEntity = reset($deferred);
1035-
$resolved[] = $deferredEntity->resolve($offline);
1031+
$resolved[] = $deferredEntity->resolve();
10361032
}
10371033
}
10381034
}
@@ -1046,19 +1042,13 @@ public function resolveDeferredEntities(
10461042
*
10471043
* @param class-string<ISyncEntity>|null $entityType
10481044
* @param class-string<ISyncEntity>|null $forEntityType
1049-
* @param bool|null $offline If `null` (the default), the local entity store
1050-
* is used if its copy of the entities is sufficiently fresh, or if the
1051-
* provider cannot be reached. If `true`, the local entity store is used
1052-
* unconditionally. If `false`, the local entity store is unconditionally
1053-
* ignored.
10541045
* @return array<ISyncEntity[]>
10551046
*/
10561047
public function resolveDeferredRelationships(
10571048
?int $fromCheckpoint = null,
1058-
?int $providerId = null,
10591049
?string $entityType = null,
10601050
?string $forEntityType = null,
1061-
?bool $offline = null
1051+
?int $providerId = null
10621052
): array {
10631053
$entityTypeId = $entityType === null
10641054
? null
@@ -1096,7 +1086,7 @@ public function resolveDeferredRelationships(
10961086
}
10971087

10981088
foreach ($relationships as $index => $deferred) {
1099-
$resolved[] = $deferred->resolve($offline);
1089+
$resolved[] = $deferred->resolve();
11001090
unset($this->DeferredRelationships[$provId][$entTypeId][$forEntTypeId][$forEntProp][$forEntId][$index]);
11011091
}
11021092
}

0 commit comments

Comments
 (0)