1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\PODataLaravel\Models; |
4
|
|
|
|
5
|
|
|
class EntityGubbins |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var string |
9
|
|
|
*/ |
10
|
|
|
private $name; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $className; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private $keyFields; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $fields; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var AssociationStubBase[] |
29
|
|
|
*/ |
30
|
|
|
private $stubs; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getName() |
36
|
|
|
{ |
37
|
|
|
return $this->name; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $name |
42
|
|
|
*/ |
43
|
|
|
public function setName($name) |
44
|
|
|
{ |
45
|
|
|
$this->name = $name; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getClassName() |
52
|
|
|
{ |
53
|
|
|
return $this->className; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $className |
58
|
|
|
*/ |
59
|
|
|
public function setClassName($className) |
60
|
|
|
{ |
61
|
|
|
$this->className = $className; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function getKeyFields() |
68
|
|
|
{ |
69
|
|
|
return $this->keyFields; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
|
|
public function getFields() |
76
|
|
|
{ |
77
|
|
|
return $this->fields; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param array $fields |
82
|
|
|
*/ |
83
|
|
|
public function setFields(array $fields) |
84
|
|
|
{ |
85
|
|
|
if (0 == count($fields)) { |
86
|
|
|
$msg = 'Fields array must not be empty'; |
87
|
|
|
throw new \Exception($msg); |
88
|
|
|
} |
89
|
|
|
$keys = []; |
90
|
|
|
foreach ($fields as $propName => $field) { |
91
|
|
|
if (!$field instanceof EntityField) { |
92
|
|
|
$msg = 'Fields array must only have EntityField objects'; |
93
|
|
|
throw new \Exception($msg); |
94
|
|
|
} |
95
|
|
|
if ($field->getIsKeyField()) { |
96
|
|
|
$keys[$propName] = $field; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
if (0 == count($keys)) { |
100
|
|
|
$msg = 'No key field supplied in fields array'; |
101
|
|
|
throw new \Exception($msg); |
102
|
|
|
} |
103
|
|
|
$this->fields = $fields; |
104
|
|
|
$this->keyFields = $keys; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return AssociationStubBase[] |
109
|
|
|
*/ |
110
|
|
|
public function getStubs() |
111
|
|
|
{ |
112
|
|
|
return $this->stubs; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param AssociationStubBase[] $stubs |
117
|
|
|
*/ |
118
|
|
|
public function setStubs($stubs) |
119
|
|
|
{ |
120
|
|
|
if (0 == count($stubs)) { |
121
|
|
|
$msg = 'Stubs array must not be empty'; |
122
|
|
|
throw new \Exception($msg); |
123
|
|
|
} |
124
|
|
|
foreach ($stubs as $field) { |
125
|
|
|
if (!$field instanceof AssociationStubBase) { |
126
|
|
|
$msg = 'Stubs array must only have AssociationStubBase objects'; |
127
|
|
|
throw new \Exception($msg); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
$this->stubs = $stubs; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|