1
|
|
|
<?php |
2
|
|
|
/******************************************************************************** |
3
|
|
|
* Apache License, Version 2.0 * |
4
|
|
|
* * |
5
|
|
|
* Copyright [2020] [Nurlan Mukhanov <[email protected]>] * |
6
|
|
|
* * |
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); * |
8
|
|
|
* you may not use this file except in compliance with the License. * |
9
|
|
|
* You may obtain a copy of the License at * |
10
|
|
|
* * |
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 * |
12
|
|
|
* * |
13
|
|
|
* Unless required by applicable law or agreed to in writing, software * |
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, * |
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
16
|
|
|
* See the License for the specific language governing permissions and * |
17
|
|
|
* limitations under the License. * |
18
|
|
|
* * |
19
|
|
|
********************************************************************************/ |
20
|
|
|
|
21
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
namespace DBD\Entity; |
24
|
|
|
|
25
|
|
|
use DBD\Entity\Common\EntityException; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class Embedded used when you generate value with view or with calculations or need |
29
|
|
|
* to decode JSON value or get iterable property |
30
|
|
|
* Should be always protected when mapped in Mapper |
31
|
|
|
* |
32
|
|
|
* @package DBD\Entity |
33
|
|
|
*/ |
34
|
|
|
class Embedded |
35
|
|
|
{ |
36
|
|
|
/** @var string MANDATORY option */ |
37
|
|
|
public const DB_TYPE = "embeddedDbType"; |
38
|
|
|
public const ENTITY_CLASS = "embeddedEntityClass"; |
39
|
|
|
public const IS_ITERABLE = "embeddedIsIterable"; |
40
|
|
|
/** @var string set to FALSE if you want to avoid exceptions for Strictly Filled Entity */ |
41
|
|
|
public const NAME = "embeddedName"; |
42
|
|
|
/** |
43
|
|
|
* Set to FALSE if you are not going to pass data, but won't set data manually, or calculate in postProcessing |
44
|
|
|
* @see Entity::postProcessing() |
45
|
|
|
* @var string $name name of the columns in view or selected with AS. |
46
|
|
|
*/ |
47
|
|
|
public $name; |
48
|
|
|
/** @var bool $isIterable */ |
49
|
|
|
public $isIterable = false; |
50
|
|
|
/** @var string $entityClass default empty. Will be converted to Entity if not null */ |
51
|
|
|
public $entityClass; |
52
|
|
|
/** @var Type $dbType */ |
53
|
|
|
public $dbType; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Embedded constructor. |
57
|
|
|
* |
58
|
|
|
* @param array|null $arrayOfValues |
59
|
|
|
* @throws EntityException |
60
|
|
|
*/ |
61
|
|
|
public function __construct(array $arrayOfValues) |
62
|
|
|
{ |
63
|
|
|
foreach ($arrayOfValues as $key => $value) { |
64
|
|
|
switch ($key) { |
65
|
|
|
case self::DB_TYPE: |
66
|
|
|
$this->dbType = $value; |
67
|
|
|
break; |
68
|
|
|
case self::ENTITY_CLASS: |
69
|
|
|
$this->entityClass = $value; |
70
|
|
|
break; |
71
|
|
|
case self::IS_ITERABLE: |
72
|
|
|
$this->isIterable = $value; |
73
|
|
|
break; |
74
|
|
|
case self::NAME: |
75
|
|
|
$this->name = $value; |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if (!isset($this->name)) { |
81
|
|
|
throw new EntityException("Embedded name not set"); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|