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

Commit ad4be59

Browse files
author
fhein
committed
Merged the performance optimization of has (PR #220) because of the
removed $resolvedAliases.
1 parent 4032bb0 commit ad4be59

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/ServiceManager.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,26 @@ public function build($name, array $options = null)
253253
*/
254254
public function has($name)
255255
{
256-
$name = $this->aliases[$name] ?? $name;
257-
$found = isset($this->services[$name]) || isset($this->factories[$name]);
258-
259-
if ($found) {
260-
return $found;
256+
// Check services and factories first to speedup the most common requests
257+
if (isset($this->services[$name]) || isset($this->factories[$name])) {
258+
return true;
261259
}
262260

263-
// Check abstract factories
261+
// Check abstract factories next
264262
foreach ($this->abstractFactories as $abstractFactory) {
265263
if ($abstractFactory->canCreate($this->creationContext, $name)) {
266264
return true;
267265
}
268266
}
269267

270-
return false;
268+
// If $name is no alias, we are done
269+
if (! isset($this->aliases[$name])) {
270+
return false;
271+
}
272+
273+
// Finally check aliases
274+
$resolvedName = $this->aliases[$name];
275+
return isset($this->services[$resolvedName]) || isset($this->factories[$resolvedName]);
271276
}
272277

273278
/**

0 commit comments

Comments
 (0)