1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Sync\Db; |
4: | |
5: | use Salient\Contract\Core\Pipeline\PipelineInterface; |
6: | use Salient\Contract\Core\ArrayMapperInterface; |
7: | use Salient\Contract\Core\Buildable; |
8: | use Salient\Contract\Core\ListConformity; |
9: | use Salient\Contract\Sync\EntitySource; |
10: | use Salient\Contract\Sync\FilterPolicy; |
11: | use Salient\Contract\Sync\SyncContextInterface; |
12: | use Salient\Contract\Sync\SyncEntityInterface; |
13: | use Salient\Contract\Sync\SyncOperation as OP; |
14: | use Salient\Core\Concern\HasBuilder; |
15: | use Salient\Sync\Support\SyncPipelineArgument; |
16: | use Salient\Sync\AbstractSyncDefinition; |
17: | use Closure; |
18: | use LogicException; |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | final class DbSyncDefinition extends AbstractSyncDefinition implements Buildable |
35: | { |
36: | |
37: | use HasBuilder; |
38: | |
39: | |
40: | protected $Table; |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | public function __construct( |
59: | string $entity, |
60: | DbSyncProvider $provider, |
61: | array $operations = [], |
62: | ?string $table = null, |
63: | int $conformity = ListConformity::PARTIAL, |
64: | ?int $filterPolicy = null, |
65: | array $overrides = [], |
66: | ?array $keyMap = null, |
67: | int $keyMapFlags = ArrayMapperInterface::ADD_UNMAPPED, |
68: | ?PipelineInterface $pipelineFromBackend = null, |
69: | ?PipelineInterface $pipelineToBackend = null, |
70: | bool $readFromList = false, |
71: | ?int $returnEntitiesFrom = null |
72: | ) { |
73: | parent::__construct( |
74: | $entity, |
75: | $provider, |
76: | $operations, |
77: | $conformity, |
78: | $filterPolicy, |
79: | $overrides, |
80: | $keyMap, |
81: | $keyMapFlags, |
82: | $pipelineFromBackend, |
83: | $pipelineToBackend, |
84: | $readFromList, |
85: | $returnEntitiesFrom |
86: | ); |
87: | |
88: | $this->Table = $table; |
89: | } |
90: | |
91: | |
92: | |
93: | |
94: | protected function getClosure(int $operation): ?Closure |
95: | { |
96: | |
97: | if ($this->Table === null) { |
98: | return null; |
99: | } |
100: | |
101: | switch ($operation) { |
102: | case OP::CREATE: |
103: | case OP::READ: |
104: | case OP::UPDATE: |
105: | case OP::DELETE: |
106: | case OP::CREATE_LIST: |
107: | case OP::READ_LIST: |
108: | case OP::UPDATE_LIST: |
109: | case OP::DELETE_LIST: |
110: | $closure = null; |
111: | break; |
112: | |
113: | default: |
114: | throw new LogicException("Invalid SyncOperation: $operation"); |
115: | } |
116: | |
117: | return $closure; |
118: | } |
119: | |
120: | public static function getReadableProperties(): array |
121: | { |
122: | return [ |
123: | ...parent::getReadableProperties(), |
124: | 'Table', |
125: | ]; |
126: | } |
127: | } |
128: | |