This extends the RedirectRoute Model. We need to re-implement everything that the PHPCR Route document adds.
Inheritance: extends Symfony\Cmf\Bundle\RoutingBundle\Model\RedirectRoute, implements Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\PrefixInterface, implements Doctrine\ODM\PHPCR\HierarchyInterface
Ejemplo n.º 1
0
 public function testRedirectName()
 {
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $redirect = new RedirectRoute();
     $redirect->setPosition($root, 'redirectName');
     $redirect->setRouteName('symfony_route');
     $redirect->setParameters(array('param' => 7));
     // parameters should be ignored in this case
     $this->getDm()->persist($redirect);
     $this->getDm()->flush();
     $this->getDm()->clear();
     $redirect = $this->getDm()->find(null, self::ROUTE_ROOT . '/redirectName');
     $response = $this->controller->redirectAction($redirect);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $this->assertSame(302, $response->getStatusCode());
     $this->assertSame('http://localhost/symfony_route_test?param=7', $response->getTargetUrl());
 }
Ejemplo n.º 2
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     $root = $manager->find(null, '/test');
     $parent = new Generic();
     $parent->setParent($root);
     $parent->setNodename('routing');
     $manager->persist($parent);
     $route = new Route();
     $route->setParentDocument($parent);
     $route->setName('route-1');
     $manager->persist($route);
     $redirectRoute = new RedirectRoute();
     $redirectRoute->setParentDocument($parent);
     $redirectRoute->setName('redirect-route-1');
     $manager->persist($redirectRoute);
     $manager->flush();
 }
Ejemplo n.º 3
0
 public function testEnhanceControllerByClass()
 {
     // put a redirect route
     $root = $this->getDm()->find(null, self::ROUTE_ROOT);
     $route = new RedirectRoute();
     $route->setRouteTarget($root);
     $route->setPosition($root, 'redirect');
     $this->getDm()->persist($route);
     $this->getDm()->flush();
     $expected = array('_controller' => 'cmf_routing.redirect_controller:redirectAction', RouteObjectInterface::ROUTE_NAME => '/test/routing/redirect');
     $request = Request::create('/redirect');
     $matches = $this->router->matchRequest($request);
     ksort($matches);
     $this->assertTrue($request->attributes->has(DynamicRouter::ROUTE_KEY));
     $this->assertEquals($expected, $matches);
 }
Ejemplo n.º 4
0
 /**
  * @expectedException \LogicException
  */
 public function testSetContent()
 {
     $content = $this->getMock('Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface');
     $redirect = new RedirectRoute();
     $redirect->setContent($content);
 }
Ejemplo n.º 5
0
 /**
  * Load routing data into the document manager.
  *
  * NOTE: We demo all possibilities. Of course, you should try to be
  * consistent in what you use and only use different things for special
  * cases.
  *
  * @param $manager \Doctrine\ODM\PHPCR\DocumentManager
  */
 public function load(ObjectManager $manager)
 {
     if (!$manager instanceof DocumentManager) {
         $class = get_class($manager);
         throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '{$class}' given.");
     }
     $session = $manager->getPhpcrSession();
     $basepath = $this->container->getParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath');
     if ($session->itemExists($basepath)) {
         $session->removeItem($basepath);
     }
     NodeHelper::createPath($session, $basepath);
     $parent = $manager->find(null, $basepath);
     $content_path = $this->container->getParameter('cmf_content.persistence.phpcr.content_basepath');
     $locales = $this->container->getParameter('locales');
     foreach ($locales as $locale) {
         $home = new Route();
         $home->setPosition($parent, $locale);
         $home->setDefault(RouteObjectInterface::TEMPLATE_NAME, 'homepage/index.html.twig');
         $home->setContent($manager->find(null, "{$content_path}/home"));
         $manager->persist($home);
         $company = new Route();
         $company->setPosition($home, 'company');
         $company->setContent($manager->find(null, "{$content_path}/company"));
         $manager->persist($company);
         $team = new Route();
         $team->setPosition($company, 'team');
         $team->setContent($manager->find(null, "{$content_path}/team"));
         $manager->persist($team);
         $more = new Route();
         $more->setPosition($company, 'more');
         $more->setContent($manager->find(null, "{$content_path}/more"));
         $manager->persist($more);
         $projects = new Route();
         $projects->setPosition($home, 'projects');
         $projects->setContent($manager->find(null, "{$content_path}/projects"));
         $manager->persist($projects);
         $cmf = new Route();
         $cmf->setPosition($projects, 'cmf');
         $cmf->setContent($manager->find(null, "{$content_path}/cmf"));
         $manager->persist($cmf);
         $seo = new Route();
         $seo->setPosition($home, 'simple-seo-example');
         $seo->setContent($manager->find(null, "{$content_path}/simple-seo-example"));
         $manager->persist($seo);
         $seo = new Route();
         $seo->setPosition($home, 'simple-seo-property');
         $seo->setContent($manager->find(null, "{$content_path}/simple-seo-property"));
         $manager->persist($seo);
         $seo = new Route();
         $seo->setPosition($home, 'demo-seo-extractor');
         $seo->setContent($manager->find(null, "{$content_path}/demo-seo-extractor"));
         $manager->persist($seo);
     }
     // demo features of routing
     // we can create routes without locales, but will lose the language context of course
     $demo = new Route();
     $demo->setPosition($parent, 'demo');
     $demo->setContent($manager->find(null, "{$content_path}/demo"));
     $demo->setDefault(RouteObjectInterface::TEMPLATE_NAME, 'demo/template_explicit.html.twig');
     $manager->persist($demo);
     // explicit template
     $template = new Route();
     $template->setPosition($demo, 'atemplate');
     $template->setContent($manager->find(null, "{$content_path}/demo_template"));
     $template->setDefault(RouteObjectInterface::TEMPLATE_NAME, 'demo/template_explicit.html.twig');
     $manager->persist($template);
     // explicit controller
     $controller = new Route();
     $controller->setPosition($demo, 'controller');
     $controller->setContent($manager->find(null, "{$content_path}/demo_controller"));
     $controller->setDefault('_controller', 'app.content_controller:specialAction');
     $manager->persist($controller);
     // type to controller mapping
     $type = new Route();
     $type->setPosition($demo, 'type');
     $type->setContent($manager->find(null, "{$content_path}/demo_type"));
     $type->setDefault('type', 'demo_type');
     $manager->persist($type);
     // class to controller mapping
     $class = new Route();
     $class->setPosition($demo, 'class');
     $class->setContent($manager->find(null, "{$content_path}/demo_class"));
     $manager->persist($class);
     // redirections
     // redirect to uri
     $redirect = new RedirectRoute();
     $redirect->setPosition($parent, 'external');
     $redirect->setUri('http://cmf.symfony.com');
     $manager->persist($redirect);
     // redirect to other doctrine route
     $redirectRoute = new RedirectRoute();
     $redirectRoute->setPosition($parent, 'short');
     $redirectRoute->setRouteTarget($cmf);
     $manager->persist($redirectRoute);
     // redirect to Symfony route
     $redirectS = new RedirectRoute();
     $redirectS->setPosition($parent, 'short1');
     $redirectS->setRouteName('test');
     $manager->persist($redirectS);
     // class to template mapping is used for all the rest
     $default_locale = $this->container->getParameter('locale');
     $singlelocale = new Route();
     $singlelocale->setPosition($manager->find(null, "{$basepath}/{$default_locale}"), 'singlelocale');
     $singlelocale->setDefault('_locale', $default_locale);
     $singlelocale->setRequirement('_locale', $default_locale);
     $singlelocale->setContent($manager->find(null, "{$content_path}/singlelocale"));
     $manager->persist($singlelocale);
     // publication demos
     $publicationDemo = new Route();
     $publicationDemo->setPosition($parent, 'publicationdemo');
     $publicationDemo->setContent($manager->find(null, "{$content_path}/publication_demo"));
     $manager->persist($publicationDemo);
     $notPublished = new Route();
     $notPublished->setPosition($publicationDemo, 'notpublished');
     $notPublished->setContent($manager->find(null, "{$content_path}/not_published"));
     $manager->persist($notPublished);
     $publishedTomorrow = new Route();
     $publishedTomorrow->setPosition($publicationDemo, 'publishedtomorrow');
     $publishedTomorrow->setContent($manager->find(null, "{$content_path}/published_tomorrow"));
     $manager->persist($publishedTomorrow);
     $manager->flush();
 }