vendor/umbrella2/corebundle/src/Menu/Builder/MenuBuilder.php line 18

Open in your IDE?
  1. <?php
  2. namespace Umbrella\CoreBundle\Menu\Builder;
  3. use Umbrella\CoreBundle\Menu\DTO\Menu;
  4. use Umbrella\CoreBundle\Menu\Visitor\MenuCurrentVisitor;
  5. use Umbrella\CoreBundle\Menu\Visitor\MenuVisibilityVisitor;
  6. class MenuBuilder
  7. {
  8.     private Menu $menu;
  9.     private MenuItemBuilder $rootBuilder;
  10.     /**
  11.      * MenuBuilder constructor.
  12.      */
  13.     public function __construct(string $name)
  14.     {
  15.         $this->menu = new Menu($name);
  16.         $this->rootBuilder = new MenuItemBuilder($this->menu->getRoot());
  17.     }
  18.     public function root(): MenuItemBuilder
  19.     {
  20.         return $this->rootBuilder;
  21.     }
  22.     public function getMenu(): Menu
  23.     {
  24.         // menu visitor isn't configurable
  25.         $this->menu
  26.             ->clearVisitors()
  27.             ->addVisitor(MenuVisibilityVisitor::class)
  28.             ->addVisitor(MenuCurrentVisitor::class);
  29.         return $this->menu;
  30.     }
  31. }