10000 [HttpKernel] fixed the inline renderer when passing objects as attrib… · symfony/symfony@82dbaee · GitHub
[go: up one dir, main page]

Skip to content

Commit 82dbaee

Browse files
committed
[HttpKernel] fixed the inline renderer when passing objects as attributes (closes #7124)
1 parent 6dbd1e1 commit 82dbaee

File tree

8 files changed

+122
-5
lines changed

8 files changed

+122
-5
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\Functional\Bundle\TestBundle\Controller;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\DependencyInjection\ContainerAware;
17+
18+
class FragmentController extends ContainerAware
19+
{
20+
public function indexAction()
21+
{
22+
$actions = $this->container->get('templating')->get('actions');
23+
24+
return new Response($actions->render($actions->controller('TestBundle:Fragment:inlined', array(
25+
'options' => array(
26+
'bar' => new Bar(),
27+
'eleven' => 11,
28+
),
29+
))));
30+
}
31+
32+
public function inlinedAction($options, $_format)
33+
{
34+
return new Response($options['bar']->getBar().' '.$_format);
35+
}
36+
}
37+
38+
class Bar
39+
{
40+
private $bar = 'bar';
41+
42+
public function getBar()
43+
{
44+
return $this->bar;
45+
}
46+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ session_showflash:
2121
profiler:
2222
path: /profiler
2323
defaults: { _controller: TestBundle:Profiler:index }
24+
25+
fragment_home:
26+
path: /fragment_home
27+
defaults: { _controller: TestBundle:Fragment:index, _format: txt }
28+
29+
fragment_inlined:
30+
path: /fragment_inlined
31+
defaults: { _controller: TestBundle:Fragment:inlined }
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\Functional;
13+
14+
/**
15+
* @group functional
16+
*/
17+
class FragmentTest extends WebTestCase
18+
{
19+
/**
20+
* @dataProvider getConfigs
21+
*/
22+
public function testFragment($insulate)
23+
{
24+
$client = $this->createClient(array('test_case' => 'Fragment', 'root_config' => 'config.yml'));
25+
if ($insulate) {
26+
$client->insulate();
27+
}
28+
29+
$client->request('GET', '/fragment_home');
30+
31+
$this->assertEquals('bar txt', $client->getResponse()->getContent());
32+
}
33+
34+
public function getConfigs()
35+
{
36+
return array(
37+
array(false),
38+
array(true),
39+
);
40+
}
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
4+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
5+
6+
return array(
7+
new FrameworkBundle(),
8+
new TestBundle(),
9+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
fragments: ~
6+
templating:
7+
engines: ['php']
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_fragmenttest_bundle:
2+
resource: @TestBundle/Resources/config/routing.yml

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ public function render($uri, Request $request, array $options = array())
4747
$reference = null;
4848
if ($uri instanceof ControllerReference) {
4949
$reference = $uri;
50+
51+
// Remove attributes from the genereated URI because if not, the Symfony
52+
// routing system will use them to populate the Request attributes. We don't
53+
// want that as we want to preserve objects (so we manually set Request attributes
54+
// below instead)
55+
$attributes = $reference->attributes;
56+
$reference->attributes = array();
5057
$uri = $this->generateFragmentUri($uri, $request);
58+
$reference->attributes = $attributes;
5159
}
5260

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ public function testRenderWithObjectsAsAttributes()
5050
$object = new \stdClass();
5151

5252
$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-
));
53+
$subRequest->attributes->replace(array('object' => $object));
5854

5955
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
6056
$kernel

0 commit comments

Comments
 (0)
0