Skip to content

Commit edfef8e

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
2 parents ae38e64 + c65267d commit edfef8e

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

Matcher/TraceableUrlMatcher.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Routing\Matcher;
1313

14+
use Symfony\Component\HttpFoundation\Request;
1415
use Symfony\Component\Routing\Exception\ExceptionInterface;
1516
use Symfony\Component\Routing\Route;
1617
use Symfony\Component\Routing\RouteCollection;
@@ -40,6 +41,15 @@ public function getTraces($pathinfo)
4041
return $this->traces;
4142
}
4243

44+
public function getTracesForRequest(Request $request)
45+
{
46+
$this->request = $request;
47+
$traces = $this->getTraces($request->getPathInfo());
48+
$this->request = null;
49+
50+
return $traces;
51+
}
52+
4353
protected function matchCollection($pathinfo, RouteCollection $routes)
4454
{
4555
foreach ($routes as $name => $route) {

README.md

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
11
Routing Component
22
=================
33

4-
Routing associates a request with the code that will convert it to a response.
5-
6-
The example below demonstrates how you can set up a fully working routing
7-
system:
8-
9-
```php
10-
use Symfony\Component\HttpFoundation\Request;
11-
use Symfony\Component\Routing\Matcher\UrlMatcher;
12-
use Symfony\Component\Routing\RequestContext;
13-
use Symfony\Component\Routing\RouteCollection;
14-
use Symfony\Component\Routing\Route;
15-
16-
$routes = new RouteCollection();
17-
$routes->add('hello', new Route('/hello', array('controller' => 'foo')));
18-
19-
$context = new RequestContext();
20-
21-
// this is optional and can be done without a Request instance
22-
$context->fromRequest(Request::createFromGlobals());
23-
24-
$matcher = new UrlMatcher($routes, $context);
25-
26-
$parameters = $matcher->match('/hello');
27-
```
4+
The Routing component maps an HTTP request to a set of configuration variables.
285

296
Resources
307
---------
318

32-
You can run the unit tests with the following command:
33-
34-
$ cd path/to/Symfony/Component/Routing/
35-
$ composer install
36-
$ phpunit
9+
* [Documentation](https://symfony.com/doc/current/components/routing/index.html)
10+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
11+
* [Report issues](https://github.com/symfony/symfony/issues) and
12+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
13+
in the [main Symfony repository](https://github.com/symfony/symfony)

Tests/Matcher/TraceableUrlMatcherTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Routing\Tests\Matcher;
1313

14+
use Symfony\Component\HttpFoundation\Request;
1415
use Symfony\Component\Routing\Route;
1516
use Symfony\Component\Routing\RouteCollection;
1617
use Symfony\Component\Routing\RequestContext;
@@ -98,4 +99,23 @@ public function getLevels($traces)
9899

99100
return $levels;
100101
}
102+
103+
public function testRoutesWithConditions()
104+
{
105+
$routes = new RouteCollection();
106+
$routes->add('foo', new Route('/foo', array(), array(), array(), 'baz', array(), array(), "request.headers.get('User-Agent') matches '/firefox/i'"));
107+
108+
$context = new RequestContext();
109+
$context->setHost('baz');
110+
111+
$matcher = new TraceableUrlMatcher($routes, $context);
112+
113+
$notMatchingRequest = Request::create('/foo', 'GET');
114+
$traces = $matcher->getTracesForRequest($notMatchingRequest);
115+
$this->assertEquals("Condition \"request.headers.get('User-Agent') matches '/firefox/i'\" does not evaluate to \"true\"", $traces[0]['log']);
116+
117+
$matchingRequest = Request::create('/foo', 'GET', array(), array(), array(), array('HTTP_USER_AGENT' => 'Firefox'));
118+
$traces = $matcher->getTracesForRequest($matchingRequest);
119+
$this->assertEquals('Route matches!', $traces[0]['log']);
120+
}
101121
}

0 commit comments

Comments
 (0)