lotriss/recursive-inherit-bundle

Inherit recursive bundle for symfony

0.1 2021-09-12 01:04 UTC

This package is auto-updated.

Last update: 2024-04-12 06:56:28 UTC


README

Build Status

Requirements

Name Version
PHP >=8.0
Symfony >=5.0

Installation

composer require lotriss/recursive-inherit-bundle

Usage

To build nested structure you need structure array where itemId is in array keys and parentId is in value. For root item value is NULL For example:

<?php
use Lotriss\RecursiveInherit\Service\StructureDataHandler;

$structureMap = [
    'parent_1' => null, //Root element
    'child_1' => 'parent_1', // Child that is under parent_1 node
    'child_parent_2' => 'parent_1', //Another child that is under parent_1 node 
    'child_3' => 'child_parent_2', // Child that is under child_parent_2 which is under parent_1 node
];

$structureMapHandler = new StructureDataHandler();
$builtStructure = $structureMapHandler->buildStructure($structureMap); 

You can define more than one root element by adding element with NULL value.

$structureMap['parent_2'] = null;
$structureMap['child_for_parent_2'] = 'parent_2';

Running tests

To run tests you can use ./run-tests.sh or docker based environment by running ./run-tests-docker.sh

In build/coverage-html you can find test coverage for this bundle after test run.