-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Fix a limitation of the PhpDumper #18167
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
Conversation
@javiereguiluz yeah I know but as @stof said #18028 (comment), @xabbuh can't use a black list without this :-/ |
$name = Container::camelize($id); | ||
$finalName = $name = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename $finalName
to $uniqueName
Thank you @javiereguiluz, I fixed your comments |
@@ -58,6 +58,7 @@ class PhpDumper extends Dumper | |||
private $targetDirRegex; | |||
private $targetDirMaxMatches; | |||
private $docStar; | |||
private $existingNames = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for bothering you again about this ... but after looking at the code with more calm, I think the "right" name for this variable would be $serviceNames
instead of $existingNames
. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem ;-)
Would you prefer $serviceIdToMethodNameMap
as proposed by @xabbuh ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to describe the purpose of the variable with absolute precision, so it's probably a good idea to make that change ... and, after that change, it's probably a good idea to change $uniqueName
to $methodName
or $serviceMethodName
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, changed
Thanks for taking care of this @Ener-Getick! I like the approach in general and just left some suggestions to improve it a bit. |
@@ -1349,13 +1351,22 @@ private function getServiceCall($id, Reference $reference = null) | |||
*/ | |||
private function camelize($id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this private method should be renamed though, as it is not about camelizing anymore, but about generating the method name
there is a another nice side-effect of this PR: |
} | ||
$this->serviceIdToMethodNameMap[$id] = $methodName; | ||
$this->usedMethodNames[$methodName] = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method names must be considered as case insensitive in this array, as PHP treats them this way. Otherwise you will still generated conflicting names
Status: Needs Review |
I updated the |
@@ -63,7 +63,7 @@ public function isProxyCandidate(Definition $definition) | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function getProxyFactoryCode(Definition $definition, $id) | |||
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an argument here is a BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if it is optional ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this was allowed... Do you have an idea how to make it work otherwise ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As child classes are allowed to add additional arguments (see https://3v4l.org/CmOt2) you could use func_num_args()
and func_get_arg()
to create a forward compatible layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well... you could do play with func_get_args
and func_num_args
: https://github.com/symfony/validator/blob/2.8/Validator/RecursiveValidator.php#L118 it isn't pretty though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 |
@@ -71,7 +71,12 @@ public function getProxyFactoryCode(Definition $definition, $id) | |||
$instantiation .= " \$this->services['$id'] ="; | |||
} | |||
|
|||
$methodName = 'get'.Container::camelize($id).'Service'; | |||
if (func_num_args() >= 3) { | |||
$methodName = func_get_arg(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be written by adding $methodName = null
in the signature of the method, and checking for null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, actually no. It would break BC for people extending the class. so forget it.
👍 Status: reviewed |
👍 |
@trousers this issues aren't related to this PR as there were already present. |
Thank you @Ener-Getick. |
The
PhpDumper
cannot currently dump several services' id containing characters unsupported by php.This PR tries to solve this issue by removing the unsupported characters and by sufixing their camelized association to avoid conflicts.