Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Routing] Add possibility to create a request context with parameters directly#60120

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alexander-schranz wants to merge6 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromalexander-schranz:enhancement/quickly-create-request-context-with-parameters

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranzalexander-schranz commentedApr 2, 2025
edited by OskarStark
Loading

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix #...
LicenseMIT

While I worked on the route integration into Sulu. I had to write a few tests for depending on the RequestContext. To improve the DX I think the parameters should be possible also inside the construct directly so instead of:

$requestContext =newRequestContext();$requestContext->setParameters(['foo' =>'bar']);$service->myMethod($requestContext);

I can do:

$service->myMethod(newRequestContext(parameters: ['foo' =>'bar']));

@@ -43,6 +43,7 @@ public function __construct(string $baseUrl = '', string $method = 'GET', string
$this->setHttpsPort($httpsPort);
$this->setPathInfo($path);
$this->setQueryString($queryString);
$this->setParameters([...$this->parameters, ...$parameters]);
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The class is not final, so we merge it with eventually parent set parameters.

Copy link
Member

Choose a reason for hiding this comment

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

which parent set parameters are you talking about ?

Copy link
ContributorAuthor

@alexander-schranzalexander-schranzApr 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

A class notfinal like RequestContext can beextends and call inside it constructor before the parent construct thesetter methods:

class MyCustomContextextends RequestContext {publicfunction__construct()     {$this->setParameters(['key' =>'value']);parent::__construct();     }}

See also new added test. Doing justsetParameters($parameters); would override existing parameters of that class.

Copy link
ContributorAuthor

@alexander-schranzalexander-schranzApr 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

we could also create a deprecationif (count($this->parameters) > 0) { and simplify this in Symfony 8?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

One other question is maybe what is expected behaviour for:

$this->setParameters(['key' =>'value']);parent::__construct(parameters: ['other' =>'test']);

If not merged we could go for bc layer with:

if (count($parameters) >0) {$this->setParameters($parameters);}elseif (count($this->parameters) >0) {trigger_deprecation('symfony/routing','7.3','Set parameters directly via the own constructor argument');}

which in 8.0 gets:

$this->setParameters($parameters);

@carsonbotcarsonbot changed the titleAdd possibility to create a request context with parameters directly[Routing] Add possibility to create a request context with parameters directlyApr 2, 2025
$this->assertEquals(['foo' => 'bar'], $requestContext->getParameters());
}

public function testConstructParametersBcLayer()

Choose a reason for hiding this comment

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

not sure what this test case is about

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

its about why theif is needed for BC reasons.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This lines. As the require for the bc case in this tests, other tests wouldn't catch that.

+        if ($parameters) {            $this->parameters = $parameters;+        }

First I wanted to trigger deprecation so we could just remove it with 8.0.

@alexander-schranzalexander-schranzforce-pushed theenhancement/quickly-create-request-context-with-parameters branch from25f7f5f to32a29d8CompareMay 26, 2025 17:51
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@alexander-schranz@nicolas-grekas@stof@fabpot@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp