-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add a deserialized Data Validator #6770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,4 +339,29 @@ class ObjectSerializer | |
return $instance; | ||
} | ||
} | ||
|
||
/** | ||
* Verify the Data structure to make sure all the objects are validated | ||
* @param mided $data object to be validated | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public static function verifyDeserializedData ($data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the design here: the data needs to be valid enough for the deserialization to take place. If that already happened, |
||
if (is_object ($data) && $data instanceof {{invokerPackage}}\Model\ModelInterface) { | ||
$a_invalidProperties = $data->listInvalidProperties(); | ||
|
||
if (count($a_invalidProperties) != 0) { | ||
throw new \InvalidArgumentException(implode (' ', $a_invalidProperties)); | ||
} | ||
|
||
foreach($data->getters() as $sProperty => &$sGetter) { | ||
self::verifyDeserializedData($data->{$sGetter}()); | ||
} | ||
|
||
} | ||
else if (is_array ($data)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inline with previous closing brace. |
||
foreach ($data as &$item) { | ||
self::verifyDeserializedData($item); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code seems to be using tabs? Spaces are used elsewhere.