public function getDefinition($name)
{
// Look for the definition by name
if (array_key_exists($name, $this->definitions)) {
return $this->castDefinition($this->definitions[$name], $name);
}
// Build the cache of wildcard definitions
if ($this->wildcardDefinitions === null) {
$this->wildcardDefinitions = [];
foreach ($this->definitions as $key => $definition) {
if (strpos($key, self::WILDCARD) !== false) {
$this->wildcardDefinitions[$key] = $definition;
}
}
}
// Look in wildcards definitions
foreach ($this->wildcardDefinitions as $key => $definition) {
// Turn the pattern into a regex
$key = preg_quote($key);
$key = '#' . str_replace('\\' . self::WILDCARD, self::WILDCARD_PATTERN, $key) . '#';
if (preg_match($key, $name, $matches) === 1) {
$definition = $this->castDefinition($definition, $name);
// For a class definition, we replace * in the class name with the matches
// *Interface -> *Impl => FooInterface -> FooImpl
if ($definition instanceof ObjectDefinition) {
array_shift($matches);
$definition->setClassName($this->replaceWildcards($definition->getClassName(), $matches));
}
return $definition;
}
}
return null;
}