8000 Merge branch '2.0' into 2.1 · loicfrering/symfony@4bee2e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bee2e9

Browse files
committed
Merge branch '2.0' into 2.1
* 2.0: [FrameworkBundle] added support for URIs as an argument to HttpKernel::render() [FrameworkBundle] restricted the type of controllers that can be executed by InternalController Making it easier to grab the PR template. fix double-decoding in the routing system Conflicts: README.md src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php src/Symfony/Component/Security/Http/HttpUtils.php
2 parents 055daa9 + 532cc9a commit 4bee2e9

File tree

5 files changed

+96
-6
lines changed

5 files changed

+96
-6
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Contributing
33

44
Symfony2 is an open source, community-driven project. If you'd like to contribute,
55
please read the [Contributing Code][1] part of the documentation. If you're submitting
6-
a pull request, please follow the guidelines in the [Submitting a Patch][2] section.
6+
a pull request, please follow the guidelines in the [Submitting a Patch][2] section
7+
and use the [Pull Request Template][3].
78

89
[1]: http://symfony.com/doc/current/contributing/code/index.html
910
[2]: http://symfony.com/doc/current/contributing/code/patches.html#check-list
11+
[3]: http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ Contributing
4646

4747
Symfony2 is an open source, community-driven project. If you'd like to contribute,
4848
please read the [Contributing Code][4] part of the documentation. If you're submitting
49-
a pull request, please follow the guidelines in the [Submitting a Patch][5] section.
49+
a pull request, please follow the guidelines in the [Submitting a Patch][5] section
50+
and use [Pull Request Template][6].
5051

5152
Running Symfony2 Tests
5253
----------------------
5354

5455
Information on how to run the Symfony2 test suite can be found in the
55-
[Running Symfony2 Tests][6] section.
56+
[Running Symfony2 Tests][7] section.
5657

5758
[1]: http://symfony.com/download
5859
[2]: http://symfony.com/get_started
5960
[3]: http://symfony.com/doc/current/
6061
[4]: http://symfony.com/doc/current/contributing/code/index.html
6162
[5]: http://symfony.com/doc/current/contributing/code/patches.html#check-list
62-
[6]: http://symfony.com/doc/master/contributing/code/tests.html
63+
[6]: http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request
64+
[7]: http://symfony.com/doc/master/contributing/code/tests.html

src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php

Lines changed: 29 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ class InternalController extends ContainerAware
3131
*/
3232
public function indexAction($path, $controller)
3333
{
34+
// safeguard
35+
if (!is_string($controller)) {
36+
throw new \RuntimeException('A Controller must be a string.');
37+
}
38+
39+
// check that the controller looks like a controller
40+
if (false === strpos($controller, '::')) {
41+
$count = substr_count($controller, ':');
42+
if (2 == $count) {
43+
// the convention already enforces the Controller suffix
44+
} elseif (1 == $count) {
45+
// controller in the service:method notation
46+
list($service, $method) = explode(':', $controller, 2);
47+
$class = get_class($this->container->get($service));
48+
49+
if (!preg_match('/Controller$/', $class)) {
50+
throw new \RuntimeException('A Controller class name must end with Controller.');
51+
}
52+
} else {
53+
throw new \LogicException('Unable to parse the Controller name.');
54+
}
55+
} else {
56+
list($class, $method) = explode('::', $controller, 2);
57+
58+
if (!preg_match('/Controller$/', $class)) {
59+
throw new \RuntimeException('A Controller class name must end with Controller.');
60+
}
61+
}
62+
3463
$request = $this->container->get('request');
3564
$attributes = $request->attributes;
3665

src/Symfony/Bundle/FrameworkBundle/HttpKernel.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,13 @@ public function render($controller, array $options = array())
139139

140140
$request = $this->container->get('request');
141141

142-
// controller or URI?
143-
if (0 === strpos($controller, '/')) {
142+
// controller or URI or path?
143+
if (0 === strpos($controller, 'http://') || 0 === strpos($controller, 'https://')) {
144+
$subRequest = Request::create($controller, 'get', array(), $request->cookies 6D40 ->all(), array(), $request->server->all());
145+
if ($session = $request->getSession()) {
146+
$subRequest->setSession($session);
147+
}
148+
} elseif (0 === strpos($controller, '/')) {
144149
$subRequest = Request::create($request->getUriForPath($controller), 'get', array(), $request->cookies->all(), array(), $request->server->all());
145150
if ($session = $request->getSession()) {
146151
$subRequest->setSession($session);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
13+
14+
use Symfony\Bundle\FrameworkBundle\Controller\InternalController;
15+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
16+
use Symfony\Component\HttpFoundation\Request;
17+
18+
class InternalControllerTest extends TestCase
19+
{
20+
/**
21+
* @expectedException \RuntimeException
22+
* @expectedExceptionMessage A Controller class name must end with Controller.
23+
*/
24+
public function testWithAClassMethodController()
25+
{
26+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
27+
28+
$controller = new InternalController();
29+
$controller->setContainer($container);
30+
31+
$controller->indexAction('/', 'Symfony\Component\HttpFoundation\Request::getPathInfo');
32+
}
33+
34+
/**
35+
* @expectedException \RuntimeException
36+
* @expectedExceptionMessage A Controller class name must end with Controller.
37+
*/
38+
public function testWithAServiceController()
39+
{
40+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
41+
$container
42+
->expects($this->once())
43+
->method('get')
44+
->will($this->returnValue(new Request()))
45+
;
46+
47+
$controller = new InternalController();
48+
$controller->setContainer($container);
49+
50+
$controller->indexAction('/', 'service:method');
51+
}
52+
}

0 commit comments

Comments
 (0)
0