private function bootstrapApp()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->register(new TwigServiceProvider(), array('twig.templates' => array('main' => '{{ knp_menu_render("my_menu", {"compressed": true}, renderer) }}')));
     $app->register(new KnpMenuServiceProvider(), array('knp_menu.menus' => array('my_menu' => 'test.menu.my')));
     $app->register(new UrlGeneratorServiceProvider());
     $app['test.menu.my'] = function (Application $app) {
         /** @var $factory \Knp\Menu\FactoryInterface */
         $factory = $app['knp_menu.factory'];
         $root = $factory->createItem('root', array('childrenAttributes' => array('class' => 'nav')));
         $root->addChild('home', array('route' => 'homepage', 'label' => 'Home'));
         $root->addChild('KnpLabs', array('uri' => 'http://knplabs.com', 'extras' => array('routes' => 'other_route')));
         return $root;
     };
     $app['test.voter'] = $app->share(function (Application $app) {
         $voter = new RouteVoter();
         $voter->setRequest($app['request']);
         return $voter;
     });
     $app['knp_menu.matcher.configure'] = $app->protect(function (Matcher $matcher) use($app) {
         $matcher->addVoter($app['test.voter']);
     });
     $app->get('/twig', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'twig'));
     })->bind('homepage');
     $app->get('/other-twig', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'twig'));
     })->bind('other_route');
     $app->get('/list', function (Application $app) {
         return $app['twig']->render('main', array('renderer' => 'list'));
     })->bind('list');
     return $app;
 }
 public function register(\Pimple $container)
 {
     $container['knp_menu.route.voter'] = $container->share(function (\Pimple $container) {
         $voter = new RouteVoter();
         $voter->setRequest($container['request_stack']->getCurrentRequest());
         return $voter;
     });
     $container['knp_menu.matcher.configure'] = $container->protect(function (Matcher $matcher) use($container) {
         $matcher->addVoter($container['knp_menu.route.voter']);
     });
 }
Esempio n. 3
0
 public function register(Application $app)
 {
     $app->register(new KnpMenuServiceProvider());
     $app['knp_menu.default_renderer'] = 'twig';
     $app['knp_menu.template'] = 'menu.twig';
     $app['route.voter'] = $app->share(function (Application $app) {
         $voter = new RouteVoter();
         $voter->setRequest($app['request']);
         return $voter;
     });
     $app['knp_menu.matcher.configure'] = $app->protect(function (Matcher $matcher) use($app) {
         $matcher->addVoter($app['route.voter']);
     });
     $app['menu'] = new Menu($app['knp_menu.factory'], new ArrayLoader($app['knp_menu.factory']));
 }
Esempio n. 4
0
 /**
  * @param string       $route
  * @param array        $parameters
  * @param string|array $itemRoutes
  * @param array        $itemsRoutesParameters
  * @param boolean      $expected
  *
  * @dataProvider provideData
  */
 public function testMatching($route, array $parameters, $itemRoutes, array $itemsRoutesParameters, $expected)
 {
     $item = $this->getMock('Knp\\Menu\\ItemInterface');
     $item->expects($this->any())->method('getExtra')->with($this->logicalOr($this->equalTo('routes'), $this->equalTo('routesParameters')))->will($this->returnCallback(function ($parameter) use($itemRoutes, $itemsRoutesParameters) {
         switch ($parameter) {
             case 'routes':
                 return $itemRoutes;
             case 'routesParameters':
                 return $itemsRoutesParameters;
         }
     }));
     $request = new Request();
     $request->attributes->set('_route', $route);
     $request->attributes->set('_route_params', $parameters);
     $voter = new RouteVoter($request);
     $this->assertSame($expected, $voter->matchItem($item));
 }