dustin/encapsulation brings intersection calculation which allows to figure out
which fields two encapsulations have in common
which fields differ between two encapsulations
which data two encapsulations have in common
which data differ between two encapsulations
Dustin\Encapsulation\IntersectionCalculation can do each of the operations from above with static method calls. But you can also use intersection calculation directly with your encapsulation objects. See the sections below if you want to know how.
Compare fields
Comparing fields will only check the existance of a field but not the containing value.
For our example we use the following two objects:
$product =newEncapsulation(['name'=>'My product','productNumber'=>'SW1002','metaTitle'=>'My cool product','ean'=>'my ean']);$category =newEncapsulation(['name'=>'My category','metaTitle'=>'My cool category','parentCategory'=>'My cool products','description'=>'These are my coolest products']);
Get field intersection
Get a list of fields which two encapsulations have in common:
'parentCategory' and 'description' are available in $category but not in $product.
Compare fields and their values
Intersection calculation can compare the data of two encapsulations. The result will always be a new encapsulation object representing the intersection or the difference. The following rules take effect:
Intersections or differences will always be in-depth which means inner collections like arrays and encapsulations will also be compared.
Inner collections will be compared together regardless of their type. No distinction is made between arrays or encapsulations.
Inner collections always result in a new encapsulation object within the result object.