|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
|
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
|
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* @author Gerrit Addiks <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Addiks\RDMBundle\ValueResolver; |
|
14
|
|
|
|
|
15
|
|
|
use Addiks\RDMBundle\ValueResolver\ValueResolverInterface; |
|
16
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
|
17
|
|
|
use Addiks\RDMBundle\Mapping\FieldMappingInterface; |
|
18
|
|
|
use Doctrine\DBAL\Schema\Column; |
|
19
|
|
|
use Addiks\RDMBundle\Exception\FailedRDMAssertionException; |
|
20
|
|
|
|
|
21
|
|
|
final class FieldValueResolver implements ValueResolverInterface |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
2 |
|
public function resolveValue( |
|
25
|
|
|
MappingInterface $fieldMapping, |
|
26
|
|
|
$entity, |
|
27
|
|
|
array $dataFromAdditionalColumns |
|
28
|
|
|
) { |
|
29
|
|
|
/** @var mixed $value */ |
|
30
|
2 |
|
$value = null; |
|
31
|
|
|
|
|
32
|
2 |
|
if ($fieldMapping instanceof FieldMappingInterface) { |
|
33
|
|
|
/** @var Column $dbalColumn */ |
|
34
|
2 |
|
$dbalColumn = $fieldMapping->getDBALColumn(); |
|
35
|
|
|
|
|
36
|
|
|
# TODO: use doctrine's field to value mapping system here (whatever that is) |
|
37
|
2 |
|
if (isset($dataFromAdditionalColumns[$dbalColumn->getName()])) { |
|
38
|
2 |
|
$value = $dataFromAdditionalColumns[$dbalColumn->getName()]; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
return $value; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public function revertValue( |
|
46
|
|
|
MappingInterface $fieldMapping, |
|
47
|
|
|
$entity, |
|
48
|
|
|
$valueFromEntityField |
|
49
|
|
|
): array { |
|
50
|
|
|
/** @var mixed $data */ |
|
51
|
2 |
|
$data = array(); |
|
52
|
|
|
|
|
53
|
2 |
|
if ($fieldMapping instanceof FieldMappingInterface) { |
|
54
|
|
|
/** @var Column $dbalColumn */ |
|
55
|
2 |
|
$dbalColumn = $fieldMapping->getDBALColumn(); |
|
56
|
|
|
|
|
57
|
|
|
# TODO: use doctrine's field to value mapping system here (whatever that is) |
|
58
|
2 |
|
$data[$dbalColumn->getName()] = $valueFromEntityField; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
return $data; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
public function assertValue( |
|
65
|
|
|
MappingInterface $fieldMapping, |
|
66
|
|
|
$entity, |
|
67
|
|
|
array $dataFromAdditionalColumns, |
|
68
|
|
|
$actualValue |
|
69
|
|
|
): void { |
|
70
|
1 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|