1 | <?php |
||
12 | trait DuplicateTrait |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $primaryKey = ''; |
||
18 | |||
19 | /** |
||
20 | * Aggregated duplicate data. |
||
21 | * |
||
22 | * @invisible |
||
23 | * @var array |
||
24 | */ |
||
25 | private $duplicates = []; |
||
26 | |||
27 | /** |
||
28 | * In many cases (for example if you have inload of HAS_MANY relation) record data can be |
||
29 | * replicated by many result rows (duplicated). To prevent wrong data linking we have to |
||
30 | * deduplicate such records. This is only internal loader functionality and required due data |
||
31 | * tree are built using php references. |
||
32 | * |
||
33 | * Method will return true if data is unique handled before and false in opposite case. |
||
34 | * Provided data array will be automatically linked with it's unique state using references. |
||
35 | * |
||
36 | * @param array $data Reference to parsed record data, reference will be pointed to valid and |
||
37 | * existed data segment if such data was already parsed. |
||
38 | * |
||
39 | * @return bool |
||
40 | */ |
||
41 | protected function deduplicate(array &$data): bool |
||
58 | |||
59 | /** |
||
60 | * Calculate duplication criteria. |
||
61 | * |
||
62 | * @param array $data |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | protected function duplicateCriteria(array &$data) |
||
70 | } |