public function lookup($type, $need = TRUE)
{
if (!isset($this->monitors[$type])) {
// not monitored or not processed yet
$obj = $this->parent;
$path = self::NAME_SEPARATOR . $this->name;
$depth = 1;
while ($obj !== NULL) {
$parent = $obj->getParent();
if ($type ? $obj instanceof $type : $parent === NULL) {
break;
}
$path = self::NAME_SEPARATOR . $obj->getName() . $path;
$depth++;
$obj = $parent;
// IComponent::getParent()
if ($obj === $this) {
$obj = NULL;
// prevent cycling
}
}
if ($obj) {
$this->monitors[$type] = [$obj, $depth, substr($path, 1), FALSE];
} else {
$this->monitors[$type] = [NULL, NULL, NULL, FALSE];
// not found
}
}
if ($need && $this->monitors[$type][0] === NULL) {
throw new Nette\InvalidStateException("Component '{$this->name}' is not attached to '{$type}'.");
}
return $this->monitors[$type][0];
}