8000 Merge branch '2.1' · loicfrering/symfony@2c9083a · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c9083a

Browse files
committed
Merge branch '2.1'
* 2.1: [FrameworkBundle] added support for URIs as an argument to HttpKernel::render() [FrameworkBundle] restricted the type of controllers that can be executed by InternalController [Process] Allow non-blocking start with PhpProcess Making it easier to grab the PR template. [Locale] fixed a test Fixed failing test fix double-decoding in the routing system Conflicts: src/Symfony/Component/Process/PhpProcess.php
2 parents eedafad + 4bee2e9 commit 2c9083a

File tree

8 files changed

+121
-19
lines changed

8 files changed

+121
-19
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
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
@@ -151,8 +151,13 @@ public function render($controller, array $options = array())
151151

152152
$request = $this->container->get('request');
153153

154-
// controller or URI?
155-
if (0 === strpos($controller, '/')) {
154+
// controller or URI or path?
155+
if (0 === strpos($controller, 'http://') || 0 === strpos($controller, 'https://')) {
156+
$subRequest = Request::create($controller, 'get', array(), $request->cookies->all(), array(), $request->server->all());
157+
if ($session = $request->getSession()) {
158+
$subRequest->setSession($session);
159+
}
160+
} elseif (0 === strpos($controller, '/')) {
156161
$subRequest = Request::create($request->getUriForPath($controller), 'get', array(), $request->cookies->all(), array(), $request->server->all());
157162
if ($session = $request->getSession()) {
158163
$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+
}

src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testGetCurrenciesDataWithUnsupportedLocale()
6666

6767
public function testGetCurrenciesData()
6868
{
69-
$symbol = $this->isSameAsIcuVersion('4.8') ? 'BR$' : 'R$';
69+
$symbol = $this->isGreaterOrEqualThanIcuVersion('4.8') ? 'BR$' : 'R$';
7070

7171
$currencies = StubLocale::getCurrenciesData('en');
7272
$this->assertEquals($symbol, $currencies['BRL']['symbol']);

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,9 @@ public function setPhpBinary($php)
5757
}
5858

5959
/**
60-
* Runs the process.
61-
*
62-
* @param Closure|string|array $callback A PHP callback to run whenever there is some
63-
* output available on STDOUT or STDERR
64-
*
65-
* @return integer The exit status code
66-
*
67-
* @throws Exception\RuntimeException
68-
*
69-
* @api
60+
* {@inheritdoc}
7061
*/
71-
public function run($callback = null)
62+
public function start($callback = null)
7263
{
7364
if (null === $this->getCommandLine()) {
7465
if (false === $php = $this->executableFinder->find()) {
@@ -77,6 +68,6 @@ public function run($callback = null)
7768
$this->setCommandLine($php);
7869
}
7970

80-
return parent::run($callback);
71+
return parent::start($callback);
8172
}
8273
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Component\Process\Tests;
4+
5+
use Symfony\Component\Process\PhpProcess;
6+
7+
class PhpProcessTest extends \PHPUnit_Framework_TestCase
8+
{
9+
10+
public function testNonBlockingWorks()
11+
{
12+
$expected = 'hello world!';
13+
$process = new PhpProcess(<<<PHP
14+
<?php echo '$expected';
15+
PHP
16+
);
17+
$process->start();
18+
$process->wait();
19+
$this->assertEquals($expected, $process->getOutput());
20+
}
21+
}

0 commit comments

Comments
 (0)
0