Allow disabling the default RouteVoter via configuration - #505
Merged
Conversation
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
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #382
Registering the built-in
RouteVoteris currently unconditional. Applications that supply their own performance-optimized voter still pay for it: the defaultRouteVoteris called for every menu item whenever a custom voter returnsnull(because it cannot decide).This adds a
route_voterboolean option (defaulttrue, so behavior is unchanged) that lets you stop the bundle from registering the defaultRouteVoter:When
false, theknp_menu.voter.routerservice definition is removed.Docs (
docs/index.rstconfig 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 XSDConfigurationTestcase now carriesroute-voter.RED — on unmodified
master(production change reverted, new tests only):GREEN — with the fix:
Baseline
masterisTests: 35with the same 15 notices / 1 skipped — this PR adds one test and introduces no new failures.composer validate --strictand PHP-CS-Fixer (--dry-run) are both clean.