Skip to content

Commit 4f5f38b

Browse files
committed
Merge pull request symfony#36 from symfony-cmf/add_uri_filter_prefix
add optional support for an uri filter pattern
2 parents 82d408a + eaec9fe commit 4f5f38b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

DynamicRouter.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,21 @@ class DynamicRouter implements RouterInterface, ChainedRouterInterface
7171
*/
7272
protected $context;
7373

74+
/**
75+
* The regexp pattern that needs to be matched before a dynamic lookup is made
76+
*
77+
* @var string
78+
*/
79+
protected $uriFilterRegexp;
80+
7481
/**
7582
* @param RouteRepositoryInterface $routeRepository The repository to get routes from
83+
* @param string $uriFilterRegexp The regexp pattern that needs to be matched before a dynamic lookup is made
7684
*/
77-
public function __construct(RouteRepositoryInterface $routeRepository)
85+
public function __construct(RouteRepositoryInterface $routeRepository, $uriFilterRegexp = '')
7886
{
7987
$this->routeRepository = $routeRepository;
88+
$this->uriFilterRegexp = $uriFilterRegexp;
8089
}
8190

8291
/**
@@ -190,6 +199,10 @@ public function getRouteCollection()
190199
*/
191200
public function match($url)
192201
{
202+
if (! empty($this->uriFilterRegexp) && ! preg_match($this->uriFilterRegexp, $url)) {
203+
throw new ResourceNotFoundException("$url does not match the '{$this->uriFilterRegexp}' pattern");
204+
}
205+
193206
$routes = $this->routeRepository->findManyByUrl($url);
194207
if (empty($routes)) {
195208
throw new ResourceNotFoundException("No routes found in the route repository for '$url'");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy