Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a priority to allow controlling the order of voters #281

Merged
merged 1 commit into from
Sep 20, 2015

Conversation

stof
Copy link
Collaborator

@stof stof commented Sep 20, 2015

The order of voters can be important in 2 cases:

  • the first voter which does not abstain wins the decision. In case multiple voters can take opposite decisions on the same item, the order is important (this will never happen for matchers shipped in the library as they either match or abstain, but never reject a match)
  • the order of matchers can affect performance: if one of the matchers performs an heavy computation, running it after other matchers can avoid calling it when another matcher is taking a decision.

Replaces #268

The order of voters can be important in 2 cases:

- the first voter which does not abstain wins the decision. In case
  multiple voters can take opposite decisions on the same item, the
  order is important (this will never happen for matchers shipped in the
  library as they either match or abstain, but never reject a match)
- the order of matchers can affect performance: if one of the matchers
  performs an heavy computation, running it after other matchers can
  avoid calling it when another matcher is taking a decision.
$sortedVoters = call_user_func_array('array_merge', $voters);

foreach ($sortedVoters as $id) {
$definition->addMethodCall('addVoter', array(new Reference($id)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the cmf chain router for example we put the priority handling into the chain router. this allows to add more voters at runtime, at the cost of having to sort them at runtime. see https://github.com/symfony-cmf/Routing/blob/master/ChainRouter.php#L80-L93 and https://github.com/symfony-cmf/Routing/blob/master/ChainRouter.php#L124-L134

both have pro and con. is it a realistic scenario that i want to add my voter in a separate compiler pass or at runtime?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, just read the discussion in KnpLabs/KnpMenu#197 so we keep as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this is what I rejected in #268. I don't want to add the concept of priorities in the library itself.

If you want to add voters in your own compiler pass by modifying the definition directly, you can still manipulate the whole list of method calls of the Definition if you don't want to add it at the end of the list (same than what you would do today).

Do you really need to register a voter at runtime ? I never faced such scenario.

@dbu
Copy link
Collaborator

dbu commented Sep 20, 2015

this is missing documentation. please add a short note where we explain how to tag voter services.

@stof
Copy link
Collaborator Author

stof commented Sep 20, 2015

@dbu we don't have any doc about registering voters currently. I will open a separate issue about that, but documenting the registration of voters should be its own PR.

@stof
Copy link
Collaborator Author

stof commented Sep 20, 2015

Actually, we already have such issue: #236

@dbu
Copy link
Collaborator

dbu commented Sep 20, 2015

agreed. added a note in #236

travis seems rather confused with the push build. either its talking to the wrong repo or there is a caching issue. i tried restarting the build but same outcome. the pr build is green however. is that enough? imho we can merge this.

@stof
Copy link
Collaborator Author

stof commented Sep 20, 2015

@dbu I pushed to the wrong remote first and delete the branch and pushed back to my fork. but Travis triggered a build for the push to the main repo, and it was the same commit.

dbu added a commit that referenced this pull request Sep 20, 2015
Add a priority to allow controlling the order of voters
@dbu dbu merged commit 340cee7 into KnpLabs:master Sep 20, 2015
@stof stof deleted the voter_order branch September 20, 2015 18:19
EmmanuelVella pushed a commit to EmmanuelVella/KnpMenuBundle that referenced this pull request Sep 23, 2020
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.

2 participants