[HttpKernel] fixed regression when rendering an inline controller and passing some objects (closes #6822)

This commit is contained in:
Fabien Potencier 2013-02-01 17:08:58 +01:00
parent 9dd43966c1
commit 8f8d6cfb15
2 changed files with 30 additions and 0 deletions

View File

@ -44,12 +44,19 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
*/
public function render($uri, Request $request, array $options = array())
{
$reference = null;
if ($uri instanceof ControllerReference) {
$reference = $uri;
$uri = $this->generateFragmentUri($uri, $request);
}
$subRequest = $this->createSubRequest($uri, $request);
// override Request attributes as they can be objects (which are not supported by the generated URI)
if (null !== $reference) {
$subRequest->attributes->add($reference->attributes);
}
$level = ob_get_level();
try {
return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);

View File

@ -45,6 +45,29 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
}
public function testRenderWithObjectsAsAttributes()
{
$object = new \stdClass();
$subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller');
$subRequest->attributes->replace(array(
'object' => $object,
'_format' => 'html',
'_controller' => 'main_controller',
));
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel
->expects($this->any())
->method('handle')
->with($subRequest)
;
$strategy = new InlineFragmentRenderer($kernel);
$strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'));
}
/**
* @expectedException \RuntimeException
*/