Skip to content

Commit

Permalink
Can now generate a flat navigation
Browse files Browse the repository at this point in the history
Need to be able to nest them into a tree
  • Loading branch information
matthewbdaly committed Sep 7, 2019
1 parent 10a952e commit a06eff5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Core/Services/Navigator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace Statico\Core\Services;

use Zend\Navigation\Navigation;
use Statico\Core\Contracts\Sources\Source;

final class Navigator
{
/**
* @var Source
*/
private $source;

public function __construct(Source $source)
{
$this->source = $source;
}

public function __invoke(): Navigation
{
$items = $this->source->all()
->map(function ($item) {
return [
'label' => $item->getField('title'),
'uri' => $item->getUrl()
];
})->toArray();
return new Navigation($items);
}
}

0 comments on commit a06eff5

Please sign in to comment.