A small utility class that accepts an array of class name, compares their class ancestories, and identifies their closest common ancestor class.
A small utility class that accepts an array of class name, compares their class ancestories, and identifies their closest common ancestor class.
Class is pretty well commented, jumping into it should answer any initial questions.
SilverStripe 4
composer require fromholdio/silverstripe-commonancestor
Assuming a page class hierarchy of:
$exampleOne = [VideoPost::class, ArticlePost::class];
$resultOne = CommonAncestor::get_closest($exampleOne);
// returns 'BlogPost'
$exampleTwo = [VideoPost::class, BlogPost::class];
$resultTwo = CommonAncestor::get_closest($exampleTwo);
// returns 'BlogPost'
$exampleThree = [VideoPost::class, BlogHolder::class];
$resultThree = CommonAncestor::get_closest($exampleThree);
// returns 'Page'
The get_closest
function also accepts a second argument, which allows you to include/exclude classes that have tables ($tablesOnly
; set to false
by default).
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem