Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4284f19

Browse files
committed
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
2 parents 21af63a + 8f8d6cf commit 4284f19

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ public function __construct(HttpKernelInterface $kernel)
4444
*/
4545
public function render($uri, Request $request, array $options = array())
4646
{
47+
$reference = null;
4748
if ($uri instanceof ControllerReference) {
49+
$reference = $uri;
4850
$uri = $this->generateFragmentUri($uri, $request);
4951
}
5052

5153
$subRequest = $this->createSubRequest($uri, $request);
5254

55+
// override Request attributes as they can be objects (which are not supported by the generated URI)
56+
if (null !== $reference) {
57+
$subRequest->attributes->add($reference->attributes);
58+
}
59+
5360
$level = ob_get_level();
5461
try {
5562
return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);

src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ public function testRenderWithControllerReference()
4545
$this->assertEquals('foo', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
4646
}
4747

48+
public function testRenderWithObjectsAsAttributes()
49+
{
50+
$object = new \stdClass();
51+
52+
$subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller');
53+
$subRequest->attributes->replace(array(
54+
'object' => $object,
55+
'_format' => 'html',
56+
'_controller' => 'main_controller',
57+
));
58+
59+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
60+
$kernel
61+
->expects($this->any())
62+
->method('handle')
63+
->with($subRequest)
64+
;
65+
66+
$strategy = new InlineFragmentRenderer($kernel);
67+
68+
$strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'));
69+
}
70+
4871
/**
4972
* @expectedException \RuntimeException
5073
*/

0 commit comments

Comments
 (0)