public function setParent(IContainer $parent = NULL, $name = NULL)
{
if ($parent === NULL && $this->parent === NULL && $name !== NULL) {
$this->name = $name;
// just rename
return $this;
} elseif ($parent === $this->parent && $name === NULL) {
return $this;
// nothing to do
}
// A component cannot be given a parent if it already has a parent.
if ($this->parent !== NULL && $parent !== NULL) {
throw new Nette\InvalidStateException("Component '{$this->name}' already has a parent.");
}
// remove from parent?
if ($parent === NULL) {
$this->refreshMonitors(0);
$this->parent = NULL;
} else {
// add to parent
$this->validateParent($parent);
$this->parent = $parent;
if ($name !== NULL) {
$this->name = $name;
}
$tmp = [];
$this->refreshMonitors(0, $tmp);
}
return $this;
}