fromholdio/silverstripe-commonancestor

A small utility class that accepts an array of class name, compares their class ancestories, and identifies their closest common ancestor class.

Installs: 455

Dependents: 3

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

1.0.0 2019-02-18 06:03 UTC

This package is auto-updated.

Last update: 2021-11-18 12:20:50 UTC


README

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.

Requirements

SilverStripe 4

Installation

composer require fromholdio/silverstripe-commonancestor

(Contrived) Example

Assuming a page class hierarchy of:

  • SiteTree
    • Page
    • BlogHolder
    • BlogPost
      • ArticlePost
      • VideoPost
$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).