4 * This file is part of the Symfony CMF package.
6 * (c) 2011-2015 Symfony CMF
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Cmf\Component\Routing;
14 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Component\Routing\Exception\RouteNotFoundException;
16 use Symfony\Component\Routing\Route;
17 use Symfony\Component\Routing\RouteCollection;
20 * Interface for the route provider the DynamicRouter is using.
22 * Typically this could be a doctrine orm or odm repository, but you can
23 * implement something else if you need to.
25 interface RouteProviderInterface
28 * Finds routes that may potentially match the request.
30 * This may return a mixed list of class instances, but all routes returned
31 * must extend the core symfony route. The classes may also implement
32 * RouteObjectInterface to link to a content document.
34 * This method may not throw an exception based on implementation specific
35 * restrictions on the url. That case is considered a not found - returning
36 * an empty array. Exceptions are only used to abort the whole request in
37 * case something is seriously broken, like the storage backend being down.
39 * Note that implementations may not implement an optimal matching
40 * algorithm, simply a reasonable first pass. That allows for potentially
41 * very large route sets to be filtered down to likely candidates, which
42 * may then be filtered in memory more completely.
44 * @param Request $request A request against which to match.
46 * @return RouteCollection with all Routes that could potentially match
47 * $request. Empty collection if nothing can match.
49 public function getRouteCollectionForRequest(Request $request);
52 * Find the route using the provided route name.
54 * @param string $name The route name to fetch.
58 * @throws RouteNotFoundException If there is no route with that name in
61 public function getRouteByName($name);
64 * Find many routes by their names using the provided list of names.
66 * Note that this method may not throw an exception if some of the routes
67 * are not found or are not actually Route instances. It will just return the
68 * list of those Route instances it found.
70 * This method exists in order to allow performance optimizations. The
71 * simple implementation could be to just repeatedly call
72 * $this->getRouteByName() while catching and ignoring eventual exceptions.
74 * If $names is null, this method SHOULD return a collection of all routes
75 * known to this provider. If there are many routes to be expected, usage of
76 * a lazy loading collection is recommended. A provider MAY only return a
77 * subset of routes to e.g. support paging or other concepts, but be aware
78 * that the DynamicRouter will only call this method once per
79 * DynamicRouter::getRouteCollection() call.
81 * @param array|null $names The list of names to retrieve, In case of null,
82 * the provider will determine what routes to return.
84 * @return Route[] Iterable list with the keys being the names from the
87 public function getRoutesByNames($names);