merged branch fabpot/render-with-objects (PR #6942)

This PR was merged into the 2.2 branch.

Commits
-------

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

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6822
| License       | MIT
| Doc PR        | n/a
This commit is contained in:
Fabien Potencier 2013-02-04 12:07:48 +01:00
commit 4284f19bd3
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
*/