Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit e1ee16e

Browse files
fheinOcramius
authored andcommitted
Removed $found variable. Reordered service resolution, so that aliases
are checked last.
1 parent 59d699b commit e1ee16e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/ServiceManager.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,27 @@ public function build($name, array $options = null)
248248
*/
249249
public function has($name)
250250
{
251-
$name = $this->resolvedAliases[$name] ?? $name;
252-
$found = isset($this->services[$name]) || isset($this->factories[$name]);
253-
254-
if ($found) {
255-
return $found;
251+
// Check services and factories first to speedup the most common requests
252+
if (isset($this->services[$name]) || isset($this->factories[$name])) {
253+
return true;
256254
}
257255

258-
// Check abstract factories
256+
// Check abstract factories next
259257
foreach ($this->abstractFactories as $abstractFactory) {
260258
if ($abstractFactory->canCreate($this->creationContext, $name)) {
261259
return true;
262260
}
263261
}
264262

263+
// If $name is no alias, we are done
264+
if (! isset($this->resolvedAliases[$name])) {
265+
return false;
266+
}
267+
268+
// Finally check aliases
269+
$name = $this->resolvedAliases[$name];
270+
return isset($this->services[$name]) || isset($this->factories[$name]);
271+
265272
return false;
266273
}
267274

0 commit comments

Comments
 (0)