Skip to content

Allow disabling the default RouteVoter via configuration - #505

Merged
garak merged 1 commit into
KnpLabs:masterfrom
ousamabenyounes:fix/issue-382
Aug 24, 2026
Merged

Allow disabling the default RouteVoter via configuration#505
garak merged 1 commit into
KnpLabs:masterfrom
ousamabenyounes:fix/issue-382

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Fix #382

Registering the built-in RouteVoter is currently unconditional. Applications that supply their own performance-optimized voter still pay for it: the default RouteVoter is called for every menu item whenever a custom voter returns null (because it cannot decide).

This adds a route_voter boolean option (default true, so behavior is unchanged) that lets you stop the bundle from registering the default RouteVoter:

knp_menu:
    route_voter: false

When false, the knp_menu.voter.router service definition is removed.

Docs (docs/index.rst config reference, all three formats) and the XSD schema were updated in the same change.

Test verification (RED → GREEN)

New tests: KnpMenuExtensionTest::testDisableRouteVoter (+ default now asserts the voter is registered) and the XSD ConfigurationTest case now carries route-voter.

RED — on unmodified master (production change reverted, new tests only):

1) ...KnpMenuExtensionTest::testDisableRouteVoter
Symfony\Component\Config\Definition\Exception\InvalidConfigurationException:
Unrecognized option "route_voter" under "knp_menu".

2) ...ConfigurationTest::testConfigurationMatchesXsd#1
Line 1: attribute 'route-voter': The attribute 'route-voter' is not allowed.

Tests: 4, Assertions: 8, Errors: 1, Failures: 1.

GREEN — with the fix:

OK, but there were issues!
Tests: 36, Assertions: 76, PHPUnit Notices: 15, Skipped: 1.

Baseline master is Tests: 35 with the same 15 notices / 1 skipped — this PR adds one test and introduces no new failures. composer validate --strict and PHP-CS-Fixer (--dry-run) are both clean.

Add a `route_voter` boolean option (default true) so applications that
provide their own performance-optimized voters can stop the bundle from
registering the built-in RouteVoter, which otherwise runs for every menu
item whenever a custom voter returns null.

Fix KnpLabs#382
@garak
garak requested a review from stof August 11, 2026 07:10
@garak
garak merged commit ee5124a into KnpLabs:master Aug 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuration to not use default RouteVoter

2 participants