Skip to content

KCESYS/php-genealogy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Genealogy

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);

About

Framework-agnostic PHP library for genealogy graph structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages