Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| MenuItem | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Components\Layout; |
| 3 | |
| 4 | use Apie\Common\MenuStructure\MenuNode; |
| 5 | use Apie\HtmlBuilders\Components\BaseComponent; |
| 6 | use Apie\HtmlBuilders\Lists\ComponentHashmap; |
| 7 | |
| 8 | class MenuItem extends BaseComponent |
| 9 | { |
| 10 | /** |
| 11 | * @param array<int, string> $currentPath |
| 12 | */ |
| 13 | public function __construct( |
| 14 | MenuNode $menuItem, |
| 15 | array $currentPath = [], |
| 16 | ) { |
| 17 | $components = []; |
| 18 | foreach ($menuItem->children as $path => $child) { |
| 19 | $components[] = new MenuItem($child, [...$currentPath, $path]); |
| 20 | } |
| 21 | parent::__construct( |
| 22 | [ |
| 23 | 'id' => $menuItem->id, |
| 24 | 'name' => $menuItem->name, |
| 25 | 'route' => $menuItem->route, |
| 26 | 'icon' => $menuItem->icon, |
| 27 | 'subcomponents' => array_keys($components), |
| 28 | ], |
| 29 | new ComponentHashmap($components) |
| 30 | ); |
| 31 | } |
| 32 | } |