-
-
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
Changes from 1 commit
b92439f
67dcb92
ae85387
5efed7b
795399a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,8 @@ class PhpDumper extends Dumper | |
private $targetDirRegex; | ||
private $targetDirMaxMatches; | ||
private $docStar; | ||
private $existingNames = array(); | ||
private $serviceIdToMethodNameMap = array(); | ||
private $usedMethodNames = array(); | ||
|
||
/** | ||
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface | ||
|
@@ -1350,21 +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 commentThe 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 |
||
{ | ||
if (isset($this->existingNames[$id])) { | ||
return $this->existingNames[$id]; | ||
if (isset($this->serviceIdToMethodNameMap[$id])) { | ||
return $this->serviceIdToMethodNameMap[$id]; | ||
} | ||
|
||
$name = Container::camelize($id); | ||
$uniqueName = $name = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $name); | ||
$prefix = 1; | ||
$methodName = $name = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $name); | ||
$suffix = 1; | ||
|
||
while (in_array($uniqueName, $this->existingNames)) { | ||
++$prefix; | ||
$uniqueName = $name.$prefix; | ||
while (isset($this->usedMethodNames[$methodName])) { | ||
++$suffix; | ||
$methodName = $name.$suffix; | ||
} | ||
$this->existingNames[$id] = $uniqueName; | ||
$this->serviceIdToMethodNameMap[$id] = $methodName; | ||
$this->usedMethodNames[$methodName] = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
return $uniqueName; | ||
return $methodName; | ||
} | ||
|
||
/** | ||
|
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 one should be initialized with all method names of the base container class (and any parent), to avoid issues
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 seems complicated to do as the base container class can be changed in the
dump()
options.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.
Using ReflectionClass gives you the info
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 meant that this parameters are different for each call to
dump()
.Anyway, I solved it by regenerating them for each call.
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.
yeah, the arrays need to be reset for each dump too anyway