KnpMenuBundle icon indicating copy to clipboard operation
KnpMenuBundle copied to clipboard

Add strict check for BuilderAliasProvider

Open vudaltsov opened this issue 9 years ago • 3 comments

I have a bundle which uses bundle:path:file.yml syntax. But since the requirements in BuilderAliasProvider are not strict enough (2 == substr_count($name, ':')), my custom Provider is not reached by the ChainProvider.

I suggest checking for smth like:

<?php

namespace Knp\Bundle\MenuBundle\Provider;

use Knp\Menu\Provider\MenuProviderInterface;

class BuilderAliasProvider implements MenuProviderInterface
{
    public function has($name, array $options = array())
    {
        return 0 < preg_match('/^\w+:[\w\\\]+:\w+$/', $name);
    }
}

vudaltsov avatar Aug 01 '16 16:08 vudaltsov

ah, and providers have no priority. that is a pitty, otherwise you could just put your provider first. i think adding a priority option to the container tag should be easy, do you want to do a pull request for that?

@stof is there a problem with the regular expression @vudaltsov proposes? could it lead to things not being accepted that are supposed to be accepted?

dbu avatar Aug 02 '16 08:08 dbu

I am happy to make a PR on whatever you decide. Imho it will be good to do both things: to add preg_match and priorities.

vudaltsov avatar Aug 02 '16 13:08 vudaltsov

lets see if @stof says something. if you want to do the priorities, i would feel confident enough to review and merge that. for the preg_match, i am more afraid of side effects and would want input from stof.

dbu avatar Aug 02 '16 14:08 dbu