Skip to content

Commit f07d44f

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 9e486a6 + 552408c commit f07d44f

File tree

3 files changed

+42
-93
lines changed

3 files changed

+42
-93
lines changed

EventListener/FragmentListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ public function onKernelRequest(GetResponseEvent $event)
5757
{
5858
$request = $event->getRequest();
5959

60-
if ($request->attributes->has('_controller') || $this->fragmentPath !== rawurldecode($request->getPathInfo())) {
60+
if ($this->fragmentPath !== rawurldecode($request->getPathInfo())) {
61+
return;
62+
}
63+
64+
if ($request->attributes->has('_controller')) {
65+
// Is a sub-request: no need to parse _path but it should still be removed from query parameters as below.
66+
$request->query->remove('_path');
67+
6168
return;
6269
}
6370

README.md

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,16 @@
11
HttpKernel Component
22
====================
33

4-
HttpKernel provides the building blocks to create flexible and fast HTTP-based
5-
frameworks.
6-
7-
``HttpKernelInterface`` is the core interface of the Symfony full-stack
8-
framework:
9-
10-
```php
11-
interface HttpKernelInterface
12-
{
13-
/**
14-
* Handles a Request to convert it to a Response.
15-
*
16-
* @param Request $request A Request instance
17-
*
18-
* @return Response A Response instance
19-
*/
20-
function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
21-
}
22-
```
23-
24-
It takes a ``Request`` as an input and should return a ``Response`` as an
25-
output. Using this interface makes your code compatible with all frameworks
26-
using the Symfony components. And this will give you many cool features for
27-
free.
28-
29-
Creating a framework based on the Symfony components is really easy. Here is
30-
a very simple, but fully-featured framework based on the Symfony components:
31-
32-
```php
33-
$routes = new RouteCollection();
34-
$routes->add('hello', new Route('/hello', array('_controller' =>
35-
function (Request $request) {
36-
return new Response(sprintf("Hello %s", $request->get('name')));
37-
}
38-
)));
39-
40-
$request = Request::createFromGlobals();
41-
42-
$context = new RequestContext();
43-
$context->fromRequest($request);
44-
45-
$matcher = new UrlMatcher($routes, $context);
46-
47-
$dispatcher = new EventDispatcher();
48-
$dispatcher->addSubscriber(new RouterListener($matcher));
49-
50-
$resolver = new ControllerResolver();
51-
52-
$kernel = new HttpKernel($dispatcher, $resolver);
53-
54-
$kernel->handle($request)->send();
55-
```
56-
57-
This is all you need to create a flexible framework with the Symfony
58-
components.
59-
60-
Want to add an HTTP reverse proxy and benefit from HTTP caching and Edge Side
61-
Includes?
62-
63-
```php
64-
$kernel = new HttpKernel($dispatcher, $resolver);
65-
66-
$kernel = new HttpCache($kernel, new Store(__DIR__.'/cache'));
67-
```
68-
69-
Want to functional test this small framework?
70-
71-
```php
72-
$client = new Client($kernel);
73-
$crawler = $client->request('GET', '/hello/Fabien');
74-
75-
$this->assertEquals('Fabien', $crawler->filter('p > span')->text());
76-
```
77-
78-
Want nice error pages instead of ugly PHP exceptions?
79-
80-
```php
81-
$dispatcher->addSubscriber(new ExceptionListener(function (Request $request) {
82-
$msg = 'Something went wrong! ('.$request->get('exception')->getMessage().')';
83-
84-
return new Response($msg, 500);
85-
}));
86-
```
87-
88-
And that's why the simple looking ``HttpKernelInterface`` is so powerful. It
89-
gives you access to a lot of cool features, ready to be used out of the box,
90-
with no efforts.
4+
The HttpKernel component provides a structured process for converting a Request
5+
into a Response by making use of the EventDispatcher component. It's flexible
6+
enough to create a full-stack framework (Symfony), a micro-framework (Silex) or
7+
an advanced CMS system (Drupal).
918

929
Resources
9310
---------
9411

95-
You can run the unit tests with the following command:
96-
97-
$ cd path/to/Symfony/Component/HttpKernel/
98-
$ composer install
99-
$ phpunit
12+
* [Documentation](https://symfony.com/doc/current/components/http_kernel/index.html)
13+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
14+
* [Report issues](https://github.com/symfony/symfony/issues) and
15+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
16+
in the [main Symfony repository](https://github.com/symfony/symfony)

Tests/EventListener/FragmentListenerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ public function testWithSignature()
8989
$this->assertFalse($request->query->has('_path'));
9090
}
9191

92+
public function testRemovesPathWithControllerDefined()
93+
{
94+
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo');
95+
96+
$listener = new FragmentListener(new UriSigner('foo'));
97+
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
98+
99+
$listener->onKernelRequest($event);
100+
101+
$this->assertFalse($request->query->has('_path'));
102+
}
103+
104+
public function testRemovesPathWithControllerNotDefined()
105+
{
106+
$signer = new UriSigner('foo');
107+
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1'));
108+
109+
$listener = new FragmentListener($signer);
110+
$event = $this->createGetResponseEvent($request);
111+
112+
$listener->onKernelRequest($event);
113+
114+
$this->assertFalse($request->query->has('_path'));
115+
}
116+
92117
private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
93118
{
94119
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, $requestType);

0 commit comments

Comments
 (0)