1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Sync; |
4: | |
5: | use Salient\Contract\Core\Provider\ProviderInterface; |
6: | use Closure; |
7: | |
8: | /** |
9: | * Base interface for providers that sync entities to and from third-party |
10: | * backends |
11: | * |
12: | * @extends ProviderInterface<SyncContextInterface> |
13: | */ |
14: | interface SyncProviderInterface extends ProviderInterface |
15: | { |
16: | /** |
17: | * @inheritDoc |
18: | */ |
19: | public function getContext(): SyncContextInterface; |
20: | |
21: | /** |
22: | * Get the provider ID assigned to the backend instance by its entity store |
23: | */ |
24: | public function getProviderId(): int; |
25: | |
26: | /** |
27: | * Get the provider's implementation of sync operations for an entity |
28: | * |
29: | * @template T of SyncEntityInterface |
30: | * |
31: | * @param class-string<T> $entity |
32: | * @return SyncDefinitionInterface<T,$this> |
33: | */ |
34: | public function getDefinition(string $entity): SyncDefinitionInterface; |
35: | |
36: | /** |
37: | * Get the provider's default unclaimed filter policy |
38: | * |
39: | * @return FilterPolicy::*|null |
40: | */ |
41: | public function getFilterPolicy(): ?int; |
42: | |
43: | /** |
44: | * True if a value is of the correct type and format to be an entity ID |
45: | * |
46: | * @param int|string $id |
47: | * @param class-string<SyncEntityInterface> $entity |
48: | */ |
49: | public function isValidIdentifier($id, string $entity): bool; |
50: | |
51: | /** |
52: | * Get the provider's entity store |
53: | */ |
54: | public function getStore(): SyncStoreInterface; |
55: | |
56: | /** |
57: | * Use an entity-agnostic interface to the provider's implementation of sync |
58: | * operations for an entity |
59: | * |
60: | * @template T of SyncEntityInterface |
61: | * |
62: | * @param class-string<T> $entity |
63: | * @return SyncEntityProviderInterface<T> |
64: | */ |
65: | public function with(string $entity, ?SyncContextInterface $context = null): SyncEntityProviderInterface; |
66: | |
67: | /** |
68: | * Perform a sync operation after validating its context |
69: | * |
70: | * @template T |
71: | * @template TOutput of iterable<T>|T |
72: | * |
73: | * @param Closure(): TOutput $operation |
74: | * @return TOutput |
75: | */ |
76: | public function runOperation(SyncContextInterface $context, Closure $operation); |
77: | |
78: | /** |
79: | * Filter the output of a sync operation if required by its context |
80: | * |
81: | * @template T of SyncEntityInterface |
82: | * @template TOutput of iterable<T>|T |
83: | * |
84: | * @param TOutput $output |
85: | * @return TOutput |
86: | */ |
87: | public function filterOperationOutput(SyncContextInterface $context, $output); |
88: | } |
89: |