public function getComponent($name, $need = TRUE)
{
if (isset($this->components[$name])) {
return $this->components[$name];
}
if (is_int($name)) {
$name = (string) $name;
} elseif (!is_string($name)) {
throw new Nette\InvalidArgumentException(sprintf('Component name must be integer or string, %s given.', gettype($name)));
} else {
$a = strpos($name, self::NAME_SEPARATOR);
if ($a !== FALSE) {
$ext = (string) substr($name, $a + 1);
$name = substr($name, 0, $a);
}
if ($name === '') {
if ($need) {
throw new Nette\InvalidArgumentException('Component or subcomponent name must not be empty string.');
}
return;
}
}
if (!isset($this->components[$name])) {
$component = $this->createComponent($name);
if ($component) {
if (!$component instanceof IComponent) {
throw new Nette\UnexpectedValueException('Method createComponent() did not return Nette\\ComponentModel\\IComponent.');
} elseif (!isset($this->components[$name])) {
$this->addComponent($component, $name);
}
}
}
if (isset($this->components[$name])) {
if (!isset($ext)) {
return $this->components[$name];
} elseif ($this->components[$name] instanceof IContainer) {
return $this->components[$name]->getComponent($ext, $need);
} elseif ($need) {
throw new Nette\InvalidArgumentException("Component with name '{$name}' is not container and cannot have '{$ext}' component.");
}
} elseif ($need) {
$hint = Nette\Utils\ObjectMixin::getSuggestion(array_merge(array_keys($this->components), array_map('lcfirst', preg_filter('#^createComponent([A-Z0-9].*)#', '$1', get_class_methods($this)))), $name);
throw new Nette\InvalidArgumentException("Component with name '{$name}' does not exist" . ($hint ? ", did you mean '{$hint}'?" : '.'));
}
}