Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpParity\Sync;
4
5/**
6 * Strategy for resolving conflicts between local and remote changes.
7 */
8enum ConflictStrategy: string
9{
10 /**
11 * Remote (AT Protocol) is source of truth.
12 * Local changes are overwritten.
13 */
14 case RemoteWins = 'remote';
15
16 /**
17 * Local database is source of truth.
18 * Remote changes are ignored.
19 */
20 case LocalWins = 'local';
21
22 /**
23 * Compare timestamps and use the newest version.
24 */
25 case NewestWins = 'newest';
26
27 /**
28 * Flag conflict for manual review.
29 * Neither version is applied automatically.
30 */
31 case Manual = 'manual';
32
33 /**
34 * Create from config value.
35 */
36 public static function fromConfig(): self
37 {
38 $strategy = config('parity.conflicts.strategy', 'remote');
39
40 return self::tryFrom($strategy) ?? self::RemoteWins;
41 }
42}