diff --git a/CmfMenuBundle.php b/CmfMenuBundle.php index b0c49155..30875470 100644 --- a/CmfMenuBundle.php +++ b/CmfMenuBundle.php @@ -22,7 +22,7 @@ class CmfMenuBundle extends Bundle public function build(ContainerBuilder $container) { parent::build($container); - $container->addCompilerPass(new AddVotersPass()); + if (class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')) { $container->addCompilerPass( DoctrinePhpcrMappingsPass::createXmlMappingDriver( diff --git a/ContentAwareFactory.php b/ContentAwareFactory.php index 8e006e40..55e8477b 100644 --- a/ContentAwareFactory.php +++ b/ContentAwareFactory.php @@ -44,31 +44,6 @@ class ContentAwareFactory extends MenuFactory */ protected $contentRouter; - /** - * Valid link types values, e.g. route, uri, content - */ - protected $linkTypes = array(); - - /** - * List of priority => array of VoterInterface - * - * @var array - */ - private $voters = array(); - - /** - * @var LoggerInterface - */ - private $logger; - - /** - * Whether to return null or a MenuItem without any URL if no URL can be - * found for a MenuNode. - * - * @var boolean - */ - private $allowEmptyItems; - /** * @param UrlGeneratorInterface $generator for the parent class * @param UrlGeneratorInterface $contentRouter to generate routes when @@ -77,51 +52,10 @@ class ContentAwareFactory extends MenuFactory * @param LoggerInterface $logger */ public function __construct( - UrlGeneratorInterface $generator, - UrlGeneratorInterface $contentRouter, - EventDispatcherInterface $dispatcher, - LoggerInterface $logger + UrlGeneratorInterface $contentRouter ) { - $this->generator = $generator; $this->contentRouter = $contentRouter; - $this->linkTypes = array('route', 'uri', 'content'); - $this->dispatcher = $dispatcher; - $this->logger = $logger; - } - - /** - * Return the linkTypes handled by this factory. - * e.g. array('uri', 'route', 'content'). - * - * @return array - */ - public function getLinkTypes() - { - return $this->linkTypes; - } - - /** - * Add a voter to decide on current item. - * - * @param VoterInterface $voter - * @param int $priority High numbers can vote first - * - * @see VoterInterface - */ - public function addCurrentItemVoter(VoterInterface $voter) - { - $this->voters[] = $voter; - } - - /** - * Get the ordered list of all menu item voters. - * - * @return VoterInterface[] - */ - private function getVoters() - { - return $this->voters; } /** @@ -181,60 +115,4 @@ public function addChildrenFromNode($nodes, ItemInterface $item) return $item; } - - /** - * Create a MenuItem. This triggers the voters to decide if its the current - * item. - * - * You can add custom link types by overwriting this method and calling the - * parent - setting the URI option and the linkType to "uri". - * - * @param string $name the menu item name - * @param array $options options for the menu item, we care about - * 'content' - * - * @return MenuItem|null Returns null if no route can be built for this menu item, - * - * @throws \RuntimeException If the stored link type is not known. - */ - public function createItem($name, array $options = array()) - { - - $current = $this->isCurrentItem($item); - - if ($current) { - $item->setCurrent(true); - } - - return $item; - } - - /** - * Cycle through all voters. If any votes true, this is the current item. If - * any votes false cycling stops. Continue cycling while we get null. - * - * @param ItemInterface $item the newly created menu item - * - * @return bool - * - * @see VoterInterface - */ - private function isCurrentItem(ItemInterface $item) - { - foreach ($this->getVoters() as $voter) { - try { - $vote = $voter->matchItem($item); - if (null ===$vote) { - continue; - } - - return $vote; - } catch (\Exception $e) { - // ignore - $this->logger->error(sprintf('Current item voter failed with: "%s"', $e->getMessage())); - } - } - - return false; - } } diff --git a/DependencyInjection/Compiler/AddVotersPass.php b/DependencyInjection/Compiler/AddVotersPass.php deleted file mode 100644 index abd0cce2..00000000 --- a/DependencyInjection/Compiler/AddVotersPass.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class AddVotersPass implements CompilerPassInterface -{ - /** - * Adds any tagged current item voters to the content aware factory - * - * @param ContainerBuilder $container - */ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition('cmf_menu.factory')) { - return; - } - - $factory = $container->getDefinition('cmf_menu.factory'); - - $voterServices = $container->findTaggedServiceIds('cmf_menu.voter'); - foreach ($voterServices as $id => $attributes) { - $factory->addMethodCall('addCurrentItemVoter', array(new Reference($id))); - } - } -} diff --git a/Provider/PhpcrMenuProvider.php b/Provider/PhpcrMenuProvider.php index 16f52d08..5b85a69f 100644 --- a/Provider/PhpcrMenuProvider.php +++ b/Provider/PhpcrMenuProvider.php @@ -171,8 +171,6 @@ public function get($name, array $options = array()) throw new \InvalidArgumentException("Menu at '$name' is misconfigured (f.e. the route might be incorrect) and could therefore not be instanciated"); } - $menuItem->setCurrentUri($this->request->getRequestUri()); - return $menuItem; } diff --git a/Resources/config/voters.xml b/Resources/config/voters.xml index b0862e9e..c542b4ad 100644 --- a/Resources/config/voters.xml +++ b/Resources/config/voters.xml @@ -12,14 +12,13 @@ - - + %cmf_menu.content_key% - - + + diff --git a/Tests/Resources/app/config/test-services.xml b/Tests/Resources/app/config/test-services.xml index 51fa5480..1cddf87e 100644 --- a/Tests/Resources/app/config/test-services.xml +++ b/Tests/Resources/app/config/test-services.xml @@ -23,8 +23,8 @@ class="Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter"> contentDocument Symfony\Cmf\Bundle\MenuBundle\Tests\Resources\Document\Post - - + + diff --git a/Voter/RequestContentIdentityVoter.php b/Voter/RequestContentIdentityVoter.php index e65cd2f5..4ca51442 100644 --- a/Voter/RequestContentIdentityVoter.php +++ b/Voter/RequestContentIdentityVoter.php @@ -12,6 +12,7 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Voter; use Knp\Menu\ItemInterface; +use Knp\Menu\Matcher\Voter\VoterInterface; use Symfony\Component\HttpFoundation\Request; /** diff --git a/Voter/RequestParentContentIdentityVoter.php b/Voter/RequestParentContentIdentityVoter.php index 000421c9..edb4f056 100644 --- a/Voter/RequestParentContentIdentityVoter.php +++ b/Voter/RequestParentContentIdentityVoter.php @@ -12,6 +12,7 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Voter; use Knp\Menu\ItemInterface; +use Knp\Menu\Matcher\Voter\VoterInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -20,7 +21,7 @@ * *getParentDocument()* is identical to the content item in the menu items extras. * * Note that there is no check, you have to make sure the $childClass does - * indeed have a getParent method. + * indeed have a getParentDocument method. * * @author David Buchmann */ @@ -46,7 +47,7 @@ class RequestParentContentIdentityVoter implements VoterInterface * attributes * @param string $childClass Fully qualified class name of the model class * the content in the request must have to - * attempt calling getParent on it. + * attempt calling getParentDocument on it. */ public function __construct($requestKey, $childClass) { diff --git a/Voter/UriPrefixVoter.php b/Voter/UriPrefixVoter.php index 3a299824..2c7405a5 100644 --- a/Voter/UriPrefixVoter.php +++ b/Voter/UriPrefixVoter.php @@ -11,11 +11,11 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Voter; +use Knp\Menu\ItemInterface; +use Knp\Menu\Matcher\Voter\VoterInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; -use Knp\Menu\ItemInterface; - /** * This voter checks if the content entry in the menu item extras is a Symfony * Route instance and if so compares its option "currentUriPrefix" with the @@ -45,7 +45,7 @@ public function setRequest(Request $request = null) */ public function matchItem(ItemInterface $item) { - if (! $this->request) { + if (!$this->request) { return null; } diff --git a/Voter/VoterInterface.php b/Voter/VoterInterface.php deleted file mode 100644 index 4113daac..00000000 --- a/Voter/VoterInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -interface VoterInterface -{ - /** - * @param ItemInterface $item - * - * @return boolean|null - */ - public function matchItem(ItemInterface $item); -}