public lookup ( $type, $need = TRUE ) : Nette\ComponentModel\IComponent | ||
리턴 | Nette\ComponentModel\IComponent |
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];
}
/** * Start download of the file! * @param IDownloader $downloader */ function download(IDownloader $downloader = null) { $this->downloader = $downloader; // Call sendResponse on presenter (used since 2.0 instead of terminate) if ($this->parent instanceof Presenter) { $presenter = $this->parent; } else { $presenter = $this->parent->lookup("Nette/Application/UI/Presenter", true); } $presenter->sendResponse($this); }