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

Appearance settings

[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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve performance
  • Loading branch information
GuilhemN committed Mar 16, 2016
commit 67dcb92118daba1bfcbca991f2c5adbfddc0d664
22 changes: 12 additions & 10 deletions 22 src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class PhpDumper extends Dumper
private $targetDirRegex;
private $targetDirMaxMatches;
private $docStar;
private $existingNames = array();
private $serviceIdToMethodNameMap = array();
private $usedMethodNames = array();
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

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 meant that this parameters are different for each call to dump().
Anyway, I solved it by regenerating them for each call.

Copy link
Member

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


/**
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
Expand Down Expand Up @@ -1350,21 +1351,22 @@ private function getServiceCall($id, Reference $reference = null)
*/
private function camelize($id)
Copy link
Member

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

{
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;
Copy link
Member

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


return $uniqueName;
return $methodName;
}

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.