addRoutes example

// DYNAMIC is supposed to be used to add new routes based upon all the     // static defined ones.     $this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::DYNAMIC);

    // ALTER is the final step to alter all the existing routes. We cannot stop     // people from adding new routes here, but we define two separate steps to     // make it clear.     $this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::ALTER);

    $this->checkProvider->setChecks($collection);

    $this->dumper->addRoutes($collection);
    $this->dumper->dump();

    $this->lock->release('router_rebuild');
    $this->dispatcher->dispatch(new Event(), RoutingEvents::FINISHED);
    $this->building = FALSE;

    $this->rebuildNeeded = FALSE;

    return TRUE;
  }

  
/** * Confirms that we can find routes with the exact incoming path. */
  public function testExactPathMatch() {
    $connection = Database::getConnection();
    $provider = new RouteProvider($connection$this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');

    $this->fixtures->createTables($connection);

    $dumper = new MatcherDumper($connection$this->state, $this->logger, 'test_routes');
    $dumper->addRoutes($this->fixtures->sampleRouteCollection());
    $dumper->dump();

    $path = '/path/one';

    $request = Request::create($path, 'GET');

    $routes = $provider->getRouteCollectionForRequest($request);

    foreach ($routes as $route) {
      $this->assertEquals($path$route->getPath(), 'Found path has correct pattern');
    }
  }
/** * Confirms that we can add routes to the dumper. */
  public function testAddRoutes() {
    $connection = Database::getConnection();
    $dumper = new MatcherDumper($connection$this->state, $this->logger);

    $route = new Route('test');
    $collection = new RouteCollection();
    $collection->add('test_route', $route);

    $dumper->addRoutes($collection);

    $dumper_routes = $dumper->getRoutes()->all();
    $collection_routes = $collection->all();

    foreach ($dumper_routes as $name => $route) {
      $this->assertEquals($collection_routes[$name]->getPath()$route->getPath(), 'Routes match');
    }
  }

  /** * Confirms that we can add routes to the dumper when it already has some. */
$this->service = $this->container->get($this->drupalProxyOriginalServiceId);
            }

            return $this->service;
        }

        /** * {@inheritdoc} */
        public function addRoutes(\Symfony\Component\Routing\RouteCollection $routes)
        {
            return $this->lazyLoadItself()->addRoutes($routes);
        }

        /** * {@inheritdoc} */
        public function dump(array $options = array (
        )): string
        {
            return $this->lazyLoadItself()->dump($options);
        }

        
Home | Imprint | This part of the site doesn't use cookies.