Skip to content

Commit

Permalink
Merge branch '2.0' into 2.1
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fabpot committed Dec 20, 2012
2 parents 055daa9 + 532cc9a commit 4bee2e9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -3,7 +3,9 @@ Contributing


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


[1]: http://symfony.com/doc/current/contributing/code/index.html [1]: http://symfony.com/doc/current/contributing/code/index.html
[2]: http://symfony.com/doc/current/contributing/code/patches.html#check-list [2]: http://symfony.com/doc/current/contributing/code/patches.html#check-list
[3]: http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -46,17 +46,19 @@ Contributing


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


Running Symfony2 Tests Running Symfony2 Tests
---------------------- ----------------------


Information on how to run the Symfony2 test suite can be found in the Information on how to run the Symfony2 test suite can be found in the
[Running Symfony2 Tests][6] section. [Running Symfony2 Tests][7] section.


[1]: http://symfony.com/download [1]: http://symfony.com/download
[2]: http://symfony.com/get_started [2]: http://symfony.com/get_started
[3]: http://symfony.com/doc/current/ [3]: http://symfony.com/doc/current/
[4]: http://symfony.com/doc/current/contributing/code/index.html [4]: http://symfony.com/doc/current/contributing/code/index.html
[5]: http://symfony.com/doc/current/contributing/code/patches.html#check-list [5]: http://symfony.com/doc/current/contributing/code/patches.html#check-list
[6]: http://symfony.com/doc/master/contributing/code/tests.html [6]: http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request
[7]: http://symfony.com/doc/master/contributing/code/tests.html
Expand Up @@ -31,6 +31,35 @@ class InternalController extends ContainerAware
*/ */
public function indexAction($path, $controller) public function indexAction($path, $controller)
{ {
// safeguard
if (!is_string($controller)) {
throw new \RuntimeException('A Controller must be a string.');
}

// check that the controller looks like a controller
if (false === strpos($controller, '::')) {
$count = substr_count($controller, ':');
if (2 == $count) {
// the convention already enforces the Controller suffix
} elseif (1 == $count) {
// controller in the service:method notation
list($service, $method) = explode(':', $controller, 2);
$class = get_class($this->container->get($service));

if (!preg_match('/Controller$/', $class)) {
throw new \RuntimeException('A Controller class name must end with Controller.');
}
} else {
throw new \LogicException('Unable to parse the Controller name.');
}
} else {
list($class, $method) = explode('::', $controller, 2);

if (!preg_match('/Controller$/', $class)) {
throw new \RuntimeException('A Controller class name must end with Controller.');
}
}

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


Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
Expand Up @@ -139,8 +139,13 @@ public function render($controller, array $options = array())


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


// controller or URI? // controller or URI or path?
if (0 === strpos($controller, '/')) { if (0 === strpos($controller, 'http://') || 0 === strpos($controller, 'https://')) {
$subRequest = Request::create($controller, 'get', array(), $request->cookies->all(), array(), $request->server->all());
if ($session = $request->getSession()) {
$subRequest->setSession($session);
}
} elseif (0 === strpos($controller, '/')) {
$subRequest = Request::create($request->getUriForPath($controller), 'get', array(), $request->cookies->all(), array(), $request->server->all()); $subRequest = Request::create($request->getUriForPath($controller), 'get', array(), $request->cookies->all(), array(), $request->server->all());
if ($session = $request->getSession()) { if ($session = $request->getSession()) {
$subRequest->setSession($session); $subRequest->setSession($session);
Expand Down
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\InternalController;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request;

class InternalControllerTest extends TestCase
{
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage A Controller class name must end with Controller.
*/
public function testWithAClassMethodController()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');

$controller = new InternalController();
$controller->setContainer($container);

$controller->indexAction('/', 'Symfony\Component\HttpFoundation\Request::getPathInfo');
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage A Controller class name must end with Controller.
*/
public function testWithAServiceController()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->once())
->method('get')
->will($this->returnValue(new Request()))
;

$controller = new InternalController();
$controller->setContainer($container);

$controller->indexAction('/', 'service:method');
}
}

0 comments on commit 4bee2e9

Please sign in to comment.