kcesys / php-genealogy
Framework-agnostic PHP library for genealogy graph structures
Installs: 104
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/kcesys/php-genealogy
Requires
- php: ^8.1
This package is auto-updated.
Last update: 2025-12-15 20:04:41 UTC
README
A framework-agnostic PHP SDK for managing genealogy data structures compatible with @kcesys/react-genealogy.
Installation
composer require kcesys/php-genealogy
Usage
Use the Builder to transform your raw data (Arrays, Objects, Database Models) into a valid Graph structure.
use KCESYS\Genealogy\Builder; $users = [ (object)['id' => 1, 'name' => 'Grandpa', 'father_id' => null], (object)['id' => 2, 'name' => 'Father', 'father_id' => 1], ]; $graph = Builder::from($users) ->mapId(fn($u) => $u->id) ->mapLabel(fn($u) => $u->name) ->mapParents(fn($u) => $u->father_id ? [$u->father_id] : []) ->build(); // Output JSON for React echo json_encode($graph);
Manual Construction
You can also build the graph manually using FamilyNode.
use KCESYS\Genealogy\GenealogyGraph; use KCESYS\Genealogy\FamilyNode; $graph = new GenealogyGraph(); $node = new FamilyNode('1', ['label' => 'Me']); $graph->addNode($node);