Skip to content
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

Add symfony request factory in sonata runtime #1739

Merged
Merged
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
16 changes: 16 additions & 0 deletions src/Runtime/SonataPagePathRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sonata\PageBundle\Runtime;

use Sonata\PageBundle\Request\SiteRequest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner;
use Symfony\Component\Runtime\RunnerInterface;
Expand All @@ -27,6 +28,21 @@ public function getRunner(?object $application): RunnerInterface
return parent::getRunner($application);
}

Request::setFactory(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok here we go, it was the reason!

into the RequestFactory, it was calling this code.

I don't know why they were adding this. does it create a main request? or does it create a new request? I am not sure. But the thing is: it solves the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ok here we go, it was the reason!

into the RequestFactory, it was calling this code.

I don't know why they were adding this. does it create a main request? or does it create a new request? I am not sure. But the thing is: it solves the issue.

yes the initial goal was to override the main request.

Copy link
Contributor Author

@eerison eerison Dec 8, 2023

Choose a reason for hiding this comment

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

do you have any idea why do we need to do this?

Well it is the same behaviour of RequestFactory, my only point here is, we don't know why do we need this.
why do we need to override the main request 😢 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

by the way issue is fixed and no extra params is needed. So this should be accepted to be merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for your information, it was an implementation from Symfony 2 🤯

2b70f81#diff-2d4fd4a3aac457940ec248d6e8421c65f88a2fc4035a3494416b29826bac53e5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by the way issue is fixed and no extra params is needed. So this should be accepted to be merged

yeah I know, I just want to know if we should add this or check if it is a main request on event.
because after this be released, I guess we can't just remove it, probably we need to keep some BC :(

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the mainRequest check, but if subrequest is used and if it is, may be siteRequest is needed. Could this Request::setFactory thing coould be deprecated for the 5.x release maybe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer the mainRequest

me too, the current approach sounds like workaround, check the main request is more common to see in symfony's doc

/**
* @param string|resource|null $content
*/
static fn (
array $query = [],
array $request = [],
array $attributes = [],
array $cookies = [],
array $files = [],
array $server = [],
$content = null
) => new SiteRequest($query, $request, $attributes, $cookies, $files, $server, $content)
);

return new HttpKernelRunner($application, SiteRequest::createFromGlobals());
}
}