NotionCommotion Posted May 31, 2018 Share Posted May 31, 2018 I have an existing MainObject which contains various sub-objects. CategoriesCollection, SeriesCollection, and PointsCollection are basically the same and are extended from parent class Collection which implements ArrayAccess, and similarly CategoryNode, SeriesNode, and PointNode are basically the same and are extended from Node. The main object is created by injecting the various sub-objects (i.e. new MainObject(new CategoryCollection(new CategoryNode()...); ) mainObject(NotionCommotion\App\Entities\MainObject)#229 (16) { ["id":protected]=> int(230) ["name":protected]=> string(4) "Test" ["categories":protected]=> object(NotionCommotion\App\Entities\CategoriesCollection)#228 (3) { ["container":protected]=> array(4) { [0]=> object(NotionCommotion\App\Entities\CategoryNode)#277 (3) { ["id":protected]=> int(132) ["name":protected]=> string(4) "test" } [1]=>.... [2]=>.... [3]=>.... } } ["series":protected]=> object(NotionCommotion\App\Entities\SeriesCollection)#215 (3) { ["container":protected]=> array(4) { [0]=> object(NotionCommotion\App\Entities\SeriesNode)#268 (4) { ["id":protected]=> int(110) ["name":protected]=> string(4) "Test" ["data":protected]=> object(NotionCommotion\App\Entities\PointsCollection)#230 (3) { ["container":protected]=> array(4) { [0]=> object(NotionCommotion\App\Entities\PointNode)#239 (4) { ["id":protected]=> int(248) ["name":protected]=> string(4) "tttt" ["units":protected]=> string(1) "F" } [1]=>.... [2]=>.... [3]=>.... } } [1]=> [2]=> [3]=> } } } } I also have a stdClass object that is a result of a user provided JSON string. It "should" have a similar structure regarding property types and quantities in the main object, quantity of items in the collections, and property types (i.e. integer, string, etc) in the nodes. I need to verify that this stdClass is valid regarding above described structure and if so update the main object and its sub-object properties with the user provided values from the stdClass object. The main object's structure as I showed it above is just one possible structure, and it could be different (i.e. different string/integer properties, no categories collection object, etc) and if so, the user provided stdClass object will need to be different to be considered valid. I am struggling how to keep it flexible and simple. High level, how would you recommend doing so? I am thinking I need to add some update() method to the MainObject class as well as CategoriesCollection, SeriesCollection, PointsCollection, CategoryNode, SeriesNode, and PointNode classes. Then inject some other object or maybe an anonymous function when creating the main and sub-objects. This is uncharted territory for me, and I would appreciate any guidance. Thank you Quote Link to comment Share on other sites More sharing options...
requinix Posted May 31, 2018 Share Posted May 31, 2018 You mean besides each class having a sort of update() method that validates the new value before trying to update? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.