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