Skip to content

Installation

phil/menu-bundle
RequirementVersionWhy
PHP8.5 or laterThe floor the bundle declares
ext-mbstringanyMessages cut in characters
phil/url^0.1.3Addresses of the web read as a browser reads them
symfony/config^8.2The configuration key
symfony/dependency-injection^8.2The bundle class and autoconfiguration
symfony/http-foundation^8.2The request the current item is read from
twig/twigoptionalThe functions and the templates
composer require phil/menu-bundle
// config/bundles.php
return [
    // ...
    Phil\MenuBundle\PhilMenuBundle::class => ['all' => true],
];

Services implementing MenuBuilder or MenuDecorator are found when the application's services are autoconfigured, as Symfony's are by default.

Configuration

One key, allow_localhost, false by default, which is also the container parameter phil_menu.allow_localhost. MenuItem::withUrl() refuses an address on localhost or under .localhost unless it is given allowLocalhost: true; a builder that links to a service of the development machine passes it the parameter:

when@dev:
    phil_menu:
        allow_localhost: true

when@test:
    phil_menu:
        allow_localhost: true
public function __construct(
    #[Autowire(param: 'phil_menu.allow_localhost')] private bool $allowLocalhost,
) {
}

// in build():
MenuItem::of('mail', 'Mail')->withUrl('http://localhost:8025/', $this->allowLocalhost);

An IP address, http://127.0.0.1:8025/, stays refused.