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

[HttpKernel] Make ServiceValueResolver work if controller namespace starts with a backslash in routing#26773

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

Merged

Conversation

@mathieutu
Copy link
Contributor

@mathieutumathieutu commentedApr 3, 2018
edited by chalasr
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#26772
LicenseMIT

Hi folks,

This PRfixes#26772:

Controller "App\Controllers\Foo" requires that you provide a value for the "$foo" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

Thank you for your work!

PS: This is my first (of many planned!) PR to Symfony, so please let me know if I did something wrong.

XenoX, kooljo, dmaicher, and Oliboy50 reacted with thumbs up emoji
@mathieutumathieutu changed the titleMake ServiceValueResolver working if controller has a backslash at first character in routing.[HttpKernel][Fix] Make ServiceValueResolver working if controller namespace start with a backslash in routing.Apr 3, 2018
@mathieutumathieutu changed the title[HttpKernel][Fix] Make ServiceValueResolver working if controller namespace start with a backslash in routing.[HttpKernel][Fix] Make ServiceValueResolver working if controller namespace starts with a backslash in routing.Apr 3, 2018
$controller =$controller[0].'::'.$controller[1];
}

$controller =ltrim($controller,'\\');

Choose a reason for hiding this comment

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

trim takes a list of characters, thus having two backslashes is redundant. You may want to use\ltrim too but not sure about the convention here

Copy link
ContributorAuthor

@mathieutumathieutuApr 3, 2018
edited
Loading

Choose a reason for hiding this comment

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

Hi@Meroje if I don't use the two backslashes, it will consider that I'm escaping the last' and never close the string:

ltrim($controller, '\')

And for the\ltrim, I've just done the same that in the rest of the code.

Choose a reason for hiding this comment

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

Ha nvm then, thought for a second it wouldn't work at the end of a string

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it's useful for ltrim:PHP-CS-Fixer/PHP-CS-Fixer#3048

Choose a reason for hiding this comment

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

It would be great to put the ltrim in a condition.
Basically, I'd suggest doing this:

if (\is_array($controller) &&\is_callable($controller,true) &&\is_string($controller[0])) {$controller =$controller[0].'::'.$controller[1];}elseif (!\is_string($controller) ||'' ===$controller) {returnfalse;}if ('\\' ===$controller[0]) {$controller =ltrim($controller,'\\');}return \$this->container->has($controller) &&$this->container->get($controller)->has($argument->getName());

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Congrats for your first PR!
Here are some nitpicking :P

$controller =$controller[0].'::'.$controller[1];
}

$controller =ltrim($controller,'\\');

Choose a reason for hiding this comment

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

It would be great to put the ltrim in a condition.
Basically, I'd suggest doing this:

if (\is_array($controller) &&\is_callable($controller,true) &&\is_string($controller[0])) {$controller =$controller[0].'::'.$controller[1];}elseif (!\is_string($controller) ||'' ===$controller) {returnfalse;}if ('\\' ===$controller[0]) {$controller =ltrim($controller,'\\');}return \$this->container->has($controller) &&$this->container->get($controller)->has($argument->getName());

$controller =$controller[0].'::'.$controller[1];
}

$controller =ltrim($controller,'\\');

Choose a reason for hiding this comment

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

consistently with the previous comment, wrap this call inif ('\\' === $controller[0]) {...}

Copy link
ContributorAuthor

@mathieutumathieutuApr 4, 2018
edited
Loading

Choose a reason for hiding this comment

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

Ok, thanks Nicolas.
One question, why the condition to format the controller if it's not an array is not the same in bothsupports andresolve methods?

Couldn't we extract this in its own method to make it consistent?

$controller =ltrim($controller,'\\');
}

return\is_string($controller) &&$this->container->has($controller) &&$this->container->get($controller)->has($argument->getName());
Copy link
Member

Choose a reason for hiding this comment

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

is_string($controller) is useless here now, as it will always betrue (due to the new check added above)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

right, thx!

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

(for 3.4)

}

return\is_string($controller) &&$this->container->has($controller) &&$this->container->get($controller)->has($argument->getName());
if ('\\' ===$controller[0]) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to test first and then trim? Why not always trim?

Choose a reason for hiding this comment

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

Trim means triggering copy-on-write when the controller string usually comes from shared memory, which means also recomputing the hash of the string, even if it doesn't change.

@stof
Copy link
Member

stof commentedApr 4, 2018

another solution could be to perform this trimming during the cache warmup of the router (we already have some logic there to resolve the bundle notation to class names there to optimize things). This way, we would have the controller class without leading backslash in the_controller key

@mathieutu
Copy link
ContributorAuthor

Yeah could be a good idea, maybe a bit more consistent, and need less operations.
As you want guys, let me know and I'll try to do it on router!

@nicolas-grekas
Copy link
Member

Worth a try for sure!

@nicolas-grekasnicolas-grekas changed the title[HttpKernel][Fix] Make ServiceValueResolver working if controller namespace starts with a backslash in routing.[HttpKernel][Fix] Make ServiceValueResolver work if controller namespace starts with a backslash in routing.Apr 5, 2018
@nicolas-grekasnicolas-grekas changed the title[HttpKernel][Fix] Make ServiceValueResolver work if controller namespace starts with a backslash in routing.[HttpKernel][Fix] Make ServiceValueResolver work if controller namespace starts with a backslash in routingApr 5, 2018
@nicolas-grekasnicolas-grekas changed the title[HttpKernel][Fix] Make ServiceValueResolver work if controller namespace starts with a backslash in routing[HttpKernel] Make ServiceValueResolver work if controller namespace starts with a backslash in routingApr 5, 2018
@Tobion
Copy link
Contributor

another solution could be to perform this trimming during the cache warmup of the router (we already have some logic there to resolve the bundle notation to class names there to optimize things).

Since the bundle notation is deprecated, this part might not survive long. So I would either do it in the Route class itself, so it it always set in a normalized way for all consumers. Or do it like proposed here.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

let's do it this way: this responsibility on ServiceValueResolver looks legit to me

@nicolas-grekasnicolas-grekas changed the base branch from4.0 to3.4April 14, 2018 15:06
@nicolas-grekasnicolas-grekasforce-pushed thefixes/route-trailing-slash branch from52ef950 to3b47441CompareApril 14, 2018 15:06
@nicolas-grekas
Copy link
Member

Thank you@mathieutu.

@nicolas-grekasnicolas-grekas merged commit3b47441 intosymfony:3.4Apr 14, 2018
nicolas-grekas added a commit that referenced this pull requestApr 14, 2018
…namespace starts with a backslash in routing (mathieutu)This PR was submitted for the 4.0 branch but it was squashed and merged into the 3.4 branch instead (closes#26773).Discussion----------[HttpKernel] Make ServiceValueResolver work if controller namespace starts with a backslash in routing| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#26772| License       | MITHi folks,This PRfixes#26772:>Controller "App\Controllers\Foo" requires that you provide a value for the "$foo" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.Thank you for your work!PS: This is my first (of many planned!) PR to Symfony, so please let me know if I did something wrong.Commits-------3b47441 [HttpKernel] Make ServiceValueResolver work if controller namespace starts with a backslash in routing
This was referencedApr 30, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+2 more reviewers

@MerojeMerojeMeroje left review comments

@linaorilinaorilinaori left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

9 participants

@mathieutu@stof@nicolas-grekas@Tobion@fabpot@Meroje@linaori@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp