Skip to content

Commit

Permalink
cs whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 12, 2021
1 parent 6969e16 commit d4da778
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ComponentModel/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final public function lookup(?string $type, bool $throw = true): ?IComponent
if ($type ? $obj instanceof $type : $parent === null) {
break;
}

$path = self::NAME_SEPARATOR . $obj->getName() . $path;
$depth++;
$obj = $parent; // IComponent::getParent()
Expand Down Expand Up @@ -96,13 +97,15 @@ final public function monitor(string $type, callable $attached = null, callable
$attached = [$this, 'attached'];
$detached = [$this, 'detached'];
}

if (
($obj = $this->lookup($type, false))
&& $attached
&& !in_array([$attached, $detached], $this->monitors[$type][3], true)
) {
$attached($obj);
}

$this->monitors[$type][3][] = [$attached, $detached]; // mark as monitored
}

Expand Down Expand Up @@ -191,6 +194,7 @@ public function setParent(?IContainer $parent, string $name = null)
$tmp = [];
$this->refreshMonitors(0, $tmp);
}

return $this;
}

Expand Down Expand Up @@ -233,7 +237,6 @@ private function refreshMonitors(int $depth, array &$missing = null, array &$lis
}
}
}

} else { // attaching
foreach ($this->monitors as $type => $rec) {
if (isset($rec[0])) { // is in cache yet
Expand All @@ -254,6 +257,7 @@ private function refreshMonitors(int $depth, array &$missing = null, array &$lis
} else {
$missing[$type] = true;
}

$this->monitors[$type][3] = $rec[3]; // mark as monitored
}
}
Expand Down Expand Up @@ -287,7 +291,6 @@ public function __clone()
if ($this->parent === null) { // not cloning
$this->refreshMonitors(0);
}

} else {
$this->parent = null;
$this->refreshMonitors(0);
Expand Down
13 changes: 12 additions & 1 deletion src/ComponentModel/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function addComponent(IComponent $component, ?string $name, string $inser
if ($obj === $component) {
throw new Nette\InvalidStateException("Circular reference detected while adding component '$name'.");
}

$obj = $obj->getParent();
} while ($obj !== null);

Expand All @@ -71,8 +72,10 @@ public function addComponent(IComponent $component, ?string $name, string $inser
if ((string) $k === $insertBefore) {
$tmp[$name] = $component;
}

$tmp[$k] = $v;
}

$this->components = $tmp;
} else {
$this->components[$name] = $component;
Expand All @@ -84,6 +87,7 @@ public function addComponent(IComponent $component, ?string $name, string $inser
unset($this->components[$name]); // undo
throw $e;
}

return $this;
}

Expand Down Expand Up @@ -116,6 +120,7 @@ final public function getComponent(string $name, bool $throw = true): ?IComponen
if ($throw) {
throw new Nette\InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given.");
}

return null;
}

Expand All @@ -136,14 +141,14 @@ final public function getComponent(string $name, bool $throw = true): ?IComponen
} elseif ($throw) {
throw new Nette\InvalidArgumentException("Component with name '$name' is not container and cannot have '$parts[1]' component.");
}

} elseif ($throw) {
$hint = Nette\Utils\ObjectHelpers::getSuggestion(array_merge(
array_map('strval', 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'?" : '.'));
}

return null;
}

Expand All @@ -165,8 +170,10 @@ protected function createComponent(string $name): ?IComponent
$class = static::class;
throw new Nette\UnexpectedValueException("Method $class::$method() did not return or create the desired component.");
}

return $component;
}

return null;
}

Expand All @@ -181,11 +188,13 @@ final public function getComponents(bool $deep = false, string $filterType = nul
if ($deep) {
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
}

if ($filterType) {
$iterator = new \CallbackFilterIterator($iterator, function ($item) use ($filterType) {
return $item instanceof $filterType;
});
}

return $iterator;
}

Expand Down Expand Up @@ -214,8 +223,10 @@ public function __clone()
foreach ($this->components as $name => $component) {
$this->components[$name] = clone $component;
}

$oldMyself->cloning = null;
}

parent::__clone();
}

Expand Down
1 change: 1 addition & 0 deletions tests/ComponentModel/Container.clone-new.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function export($obj)
$res['children'][$name] = export($child);
}
}

return $res;
}

Expand Down
1 change: 1 addition & 0 deletions tests/ComponentModel/Container.clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function export($obj)
$res['children'][$name] = export($child);
}
}

return $res;
}

Expand Down

0 comments on commit d4da778

Please sign in to comment.