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

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ public function __construct(HttpKernelInterface $kernel)
*/
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ public function testRenderWithControllerReference()
$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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are = and & encoded? This should not be the case. In encoded form it means something complete different.
So in this case it must not even work. If it doesnt matter whether they are encoded or not, then it's a bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are encoded because the whole thing is the value for the _path parameter. If you use = and & instead, it would not work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but why is it called _path then? It does not look like a path to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the items are the key/value pairs you would have used for the placeholder in the path if you would have created a dedicated route.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it should be called something like _params. Because there are placeholders also in the host.

$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
*/
Expand Down