|
1
|
|
|
<?php |
|
2
|
|
|
//[PHPCOMPRESSOR(remove,start)] |
|
3
|
|
|
/** |
|
4
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
|
5
|
|
|
* on 22.03.16 at 17:50 |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace samsonframework\orm\generator; |
|
8
|
|
|
|
|
9
|
|
|
use samsonframework\orm\generator\metadata\RealMetadata; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Real database instances class generator. |
|
13
|
|
|
* |
|
14
|
|
|
* @package samsonframework\orm\generator |
|
15
|
|
|
*/ |
|
16
|
|
|
class RealEntity extends Generic |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Class definition generation part. |
|
20
|
|
|
* |
|
21
|
|
|
* @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function createDefinition($metadata) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->generator |
|
26
|
|
|
->multiComment(array('"' . $metadata->entity . '" database entity class')) |
|
27
|
|
|
->defClass($this->className, '\\' . \samsonframework\orm\Record::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class constants generation part. |
|
32
|
|
|
* |
|
33
|
|
|
* @param RealMetadata $metadata Entity metadata |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function createConstants($metadata) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->generator |
|
38
|
|
|
->commentVar('string', 'Entity full class name, use ::class instead') |
|
39
|
|
|
->defClassConst('ENTITY', $metadata->entityClassName) |
|
40
|
|
|
->commentVar('string', 'Entity primary field name') |
|
41
|
|
|
->defClassConst('F_PRIMARY', $metadata->primaryField) |
|
42
|
|
|
->commentVar('string', 'Entity deleted flag field name') |
|
43
|
|
|
->defClassConst('F_DELETION', 'Active') |
|
44
|
|
|
->commentVar('string', 'Entity manager full class name') |
|
45
|
|
|
->defClassConst('MANAGER', $metadata->entityClassName . 'Query'); |
|
46
|
|
|
|
|
47
|
|
|
// Create all entity fields constants storing each additional field metadata |
|
48
|
|
|
foreach ($metadata->fields as $fieldID => $fieldName) { |
|
49
|
|
|
$this->generator |
|
50
|
|
|
->commentVar('string', $fieldName . ' entity field') |
|
51
|
|
|
->defClassConst('F_' . $fieldName, $fieldName); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Class static fields generation part. |
|
57
|
|
|
* |
|
58
|
|
|
* @param RealMetadata $metadata Entity metadata |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function createStaticFields($metadata) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->generator |
|
63
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
64
|
|
|
// ->defClassVar('$_sql_select', 'public static ', $metadata->arSelect) |
|
65
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
66
|
|
|
// ->defClassVar('$_attributes', 'public static ', $metadata->arAttributes) |
|
67
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
68
|
|
|
// ->defClassVar('$_types', 'public static ', $metadata->arTypes) |
|
69
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
70
|
|
|
// ->defClassVar('$_table_attributes', 'public static ', $metadata->arTableAttributes) |
|
71
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
72
|
|
|
// ->defClassVar('$_map', 'public static ', $metadata->arMap) |
|
73
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
74
|
|
|
// ->defClassVar('$_sql_from', 'public static ', $metadata->arFrom) |
|
75
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
76
|
|
|
// ->defClassVar('$_own_group', 'public static ', $metadata->arGroup) |
|
77
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
78
|
|
|
// ->defClassVar('$_relation_alias', 'public static ', $metadata->arRelationAlias) |
|
79
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
80
|
|
|
// ->defClassVar('$_relation_type', 'public static ', $metadata->arRelationType) |
|
81
|
|
|
// ->commentVar('array', '@deprecated Old ActiveRecord data') |
|
82
|
|
|
// ->defClassVar('$_relations', 'public static ', $metadata->arRelations) |
|
83
|
|
|
->commentVar('string', '@deprecated Entity table primary field name') |
|
84
|
|
|
->defClassVar('$_primary', 'public static', $metadata->primaryField) |
|
85
|
|
|
->commentVar('array', '@deprecated Entity fields and aliases') |
|
86
|
|
|
->defClassVar('$_attributes', 'public static', $metadata->fields) |
|
87
|
|
|
->commentVar('array', '@deprecated Old ActiveRecord data') |
|
88
|
|
|
->defClassVar('$fieldIDs', 'public static ', $metadata->fields); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Class fields generation part. |
|
93
|
|
|
* |
|
94
|
|
|
* @param RealMetadata $metadata Entity metadata |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function createFields($metadata) |
|
97
|
|
|
{ |
|
98
|
|
|
foreach ($metadata->fields as $fieldID => $fieldName) { |
|
99
|
|
|
$this->generator |
|
100
|
|
|
->commentVar($metadata->types[$fieldID], $fieldName . ' entity field') |
|
101
|
|
|
->defClassVar('$' . $fieldName, 'public'); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
|
106
|
|
|
|