|
@@ -60,7 +60,7 @@ abstract class LuDbo implements \JsonSerializable {
|
60
|
60
|
return $obj;
|
61
|
61
|
}
|
62
|
62
|
|
63
|
|
- public static function deserializeValue($value, $type) {
|
|
63
|
+ public static function deserializeValue($value, $type, $constraints = []) {
|
64
|
64
|
if (is_null($value)) {
|
65
|
65
|
return null;
|
66
|
66
|
}
|
|
@@ -74,18 +74,22 @@ abstract class LuDbo implements \JsonSerializable {
|
74
|
74
|
|
75
|
75
|
if ($type == "string") {
|
76
|
76
|
$dbo = LuStringDbo::jsonDeserialize($value);
|
|
77
|
+ $dbo->checkConstraints($constraints);
|
77
|
78
|
return $dbo->getString();
|
78
|
79
|
}
|
79
|
80
|
else if ($type == "int") {
|
80
|
81
|
$dbo = LuIntDbo::jsonDeserialize($value);
|
|
82
|
+ $dbo->checkConstraints($constraints);
|
81
|
83
|
return $dbo->getInt();
|
82
|
84
|
}
|
83
|
85
|
else if ($type == "float") {
|
84
|
86
|
$dbo = LuFloatDbo::jsonDeserialize($value);
|
|
87
|
+ $dbo->checkConstraints($constraints);
|
85
|
88
|
return $dbo->getFloat();
|
86
|
89
|
}
|
87
|
90
|
else if ($type == "bool") {
|
88
|
91
|
$dbo = LuBoolDbo::jsonDeserialize($value);
|
|
92
|
+ $dbo->checkConstraints($constraints);
|
89
|
93
|
return $dbo->getBool();
|
90
|
94
|
}
|
91
|
95
|
else if ($type == "mixed") {
|
|
@@ -98,12 +102,15 @@ abstract class LuDbo implements \JsonSerializable {
|
98
|
102
|
$type = substr($type, 0, strlen($type) - 2);
|
99
|
103
|
$data = [];
|
100
|
104
|
foreach ($value as $v) {
|
101
|
|
- $data[] = self::deserializeValue($v, $type);
|
|
105
|
+ $value = self::deserializeValue($v, $type, $constraints);
|
|
106
|
+ $data[] = $value;
|
102
|
107
|
}
|
103
|
108
|
return $data;
|
104
|
109
|
}
|
105
|
110
|
else {
|
106
|
|
- return call_user_func_array(array($type, "jsonDeserialize"), array($value));
|
|
111
|
+ $value = call_user_func_array(array($type, "jsonDeserialize"), array($value));
|
|
112
|
+ $value->checkConstraints($constraints);
|
|
113
|
+ return $value;
|
107
|
114
|
}
|
108
|
115
|
}
|
109
|
116
|
|
|
@@ -138,9 +145,7 @@ abstract class LuDbo implements \JsonSerializable {
|
138
|
145
|
}
|
139
|
146
|
|
140
|
147
|
if (!is_null($doc) && !is_null($value)) {
|
141
|
|
- foreach ($doc->getConstraints() as $constraint) {
|
142
|
|
- call_user_func_array([$value, $constraint->getMethod()], $constraint->getArguments());
|
143
|
|
- }
|
|
148
|
+ $value->checkConstraints($doc->getConstraints());
|
144
|
149
|
}
|
145
|
150
|
$property->setAccessible(true);
|
146
|
151
|
$property->setValue($dbo, $value);
|
|
@@ -148,6 +153,15 @@ abstract class LuDbo implements \JsonSerializable {
|
148
|
153
|
return $dbo;
|
149
|
154
|
}
|
150
|
155
|
|
|
156
|
+ /**
|
|
157
|
+ * @param $constraints LuParameterConstraintDbo[]
|
|
158
|
+ */
|
|
159
|
+ public function checkConstraints($constraints) {
|
|
160
|
+ foreach ($constraints as $constraint) {
|
|
161
|
+ call_user_func_array([$this, $constraint->getMethod()], $constraint->getArguments());
|
|
162
|
+ }
|
|
163
|
+ }
|
|
164
|
+
|
151
|
165
|
/**
|
152
|
166
|
* Generate a sample JSON object for the DBO
|
153
|
167
|
* @return array
|