-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Include ids from method map in known services #19690
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,9 +191,7 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) | |
$this->scopedServices[$scope][$id] = $service; | ||
} | ||
|
||
if (isset($this->aliases[$id])) { | ||
unset($this->aliases[$id]); | ||
} | ||
unset($this->aliases[$id], $this->methodMap[$id]); | ||
|
||
$this->services[$id] = $service; | ||
|
||
|
@@ -222,6 +220,7 @@ public function has($id) | |
for ($i = 2;;) { | ||
if ('service_container' === $id | ||
|| isset($this->aliases[$id]) | ||
|| isset($this->methodMap[$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. 👍 |
||
|| isset($this->services[$id]) | ||
) { | ||
return true; | ||
|
@@ -357,15 +356,20 @@ public function initialized($id) | |
*/ | ||
public function getServiceIds() | ||
{ | ||
$ids = array(); | ||
$ids = array_keys($this->methodMap + $this->services); | ||
$reversedMethodMap = array_change_key_case(array_flip($this->methodMap), \CASE_LOWER); | ||
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. I don't think the changes on this method are legitimate: 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. Tests proves it works... you cant imagine how creative users can be. Sorry, couldnt resist ;-)
What if we make it a feature? 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.
except that as you spotted, it never worked :)
then it should go on master and should have a supporting use case 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. You're right, i didnt consider However, they can get suffixed due duplicate methods, but that doesnt mean the id should change as well (this is the key in I covered exactly that in tests (imagine a suffixed/generated method though). |
||
foreach (get_class_methods($this) as $method) { | ||
if (preg_match('/^get(.+)Service$/', $method, $match)) { | ||
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. So, shouldn't we remove this and rely sololy on methodMap? the full method could be reduced to the following implementation, isn't it?: public function getServiceIds()
{
return array_keys($this->methodMap + $this->services);
} 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. Depends how this method should work before/after compilation. We could lazily load the method map when needed, which also happens when dumping. Im assuming the methods wont change during runtime anyway :) |
||
$ids[] = self::underscore($match[1]); | ||
if (isset($reversedMethodMap[$methodLc = 'get'.strtolower($match[1]).'service'])) { | ||
$ids[] = $reversedMethodMap[$methodLc]; | ||
} else { | ||
$ids[] = self::underscore($match[1]); | ||
} | ||
} | ||
} | ||
$ids[] = 'service_container'; | ||
|
||
return array_unique(array_merge($ids, array_keys($this->services))); | ||
return array_values(array_unique($ids)); | ||
} | ||
|
||
/** | ||
|
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 won't have any practical effect because
$this->services[$id]
is checked first in the get() methodThere 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.
For the record, I'd be 👎 now, because that would trigger a not-required copy-on-write for
$this->methodMap
.