|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_mapper\Mappers; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\MapperException; |
|
7
|
|
|
use kalanis\kw_mapper\Records; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class APreset |
|
12
|
|
|
* @package kalanis\kw_mapper\Mappers |
|
13
|
|
|
* Abstract for manipulation with constant content as table |
|
14
|
|
|
* |
|
15
|
|
|
* You just need to extend this class and set datasource array and correct map. |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class APreset extends AMapper |
|
18
|
|
|
{ |
|
19
|
|
|
use TFinder; |
|
20
|
|
|
use TStore; |
|
21
|
|
|
|
|
22
|
2 |
|
public function getAlias(): string |
|
23
|
|
|
{ |
|
24
|
2 |
|
return $this->getSource(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
protected function insertRecord(Records\ARecord $record): bool |
|
28
|
|
|
{ |
|
29
|
1 |
|
throw new MapperException('Cannot insert record into predefined array'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
protected function updateRecord(Records\ARecord $record): bool |
|
33
|
|
|
{ |
|
34
|
1 |
|
throw new MapperException('Cannot update record in predefined array'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param Records\ARecord|Records\PageRecord $record |
|
39
|
|
|
* @throws MapperException |
|
40
|
|
|
* @return int |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function countRecord(Records\ARecord $record): int |
|
43
|
|
|
{ |
|
44
|
1 |
|
$matches = $this->findMatched($record); |
|
45
|
1 |
|
return count($matches); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param Records\ARecord|Records\PageRecord $record |
|
50
|
|
|
* @throws MapperException |
|
51
|
|
|
* @return bool |
|
52
|
|
|
*/ |
|
53
|
1 |
|
protected function loadRecord(Records\ARecord $record): bool |
|
54
|
|
|
{ |
|
55
|
1 |
|
$matches = $this->findMatched($record); |
|
56
|
1 |
|
if (empty($matches)) { // nothing found |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
$dataLine = & $this->records[reset($matches)]; |
|
61
|
1 |
|
foreach ($this->getRelations() as $objectKey => $recordKey) { |
|
62
|
1 |
|
$entry = $record->getEntry($objectKey); |
|
63
|
1 |
|
$entry->setData($dataLine->offsetGet($objectKey), true); |
|
64
|
|
|
} |
|
65
|
1 |
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
protected function deleteRecord(Records\ARecord $record): bool |
|
69
|
|
|
{ |
|
70
|
1 |
|
throw new MapperException('Cannot delete record in predefined array'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param Records\ARecord $record |
|
75
|
|
|
* @throws MapperException |
|
76
|
|
|
* @return Records\ARecord[] |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function loadMultiple(Records\ARecord $record): array |
|
79
|
|
|
{ |
|
80
|
1 |
|
$toLoad = $this->findMatched($record); |
|
81
|
|
|
|
|
82
|
1 |
|
$result = []; |
|
83
|
1 |
|
foreach ($toLoad as $key) { |
|
84
|
1 |
|
$result[] = $this->records[$key]; |
|
85
|
|
|
} |
|
86
|
1 |
|
return $result; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param array<string|int, string|int|float|array<string|int, string|int|array<string|int, string|int>>> $content |
|
91
|
|
|
* @return bool |
|
92
|
|
|
* @throws MapperException |
|
93
|
|
|
* @codeCoverageIgnore should not be accessable |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function saveToStorage(array $content): bool |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
throw new MapperException('Cannot save records in predefined array'); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.