From: Cyperghost Date: Tue, 19 Nov 2024 10:25:16 +0000 (+0100) Subject: Add `IObjectTreeNode` interface to `PageNode` X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ef3be2270b9f7c014b8ea703b365b19912abf464;p=GitHub%2FWoltLab%2FWCF.git Add `IObjectTreeNode` interface to `PageNode` --- diff --git a/wcfsetup/install/files/lib/data/page/PageNode.class.php b/wcfsetup/install/files/lib/data/page/PageNode.class.php index 9822cbe042..36cc0283ac 100644 --- a/wcfsetup/install/files/lib/data/page/PageNode.class.php +++ b/wcfsetup/install/files/lib/data/page/PageNode.class.php @@ -3,6 +3,8 @@ namespace wcf\data\page; use wcf\data\DatabaseObjectDecorator; +use wcf\data\IObjectTreeNode; +use wcf\data\TObjectTreeNode; /** * Represents a page node element. @@ -15,30 +17,15 @@ use wcf\data\DatabaseObjectDecorator; * @method Page getDecoratedObject() * @mixin Page */ -class PageNode extends DatabaseObjectDecorator implements \Countable, \RecursiveIterator +class PageNode extends DatabaseObjectDecorator implements IObjectTreeNode { - /** - * parent node - * @var PageNode - */ - protected $parentNode; - - /** - * children of this node - * @var PageNode[] - */ - protected $children = []; + use TObjectTreeNode; /** * node depth */ protected int $depth = 0; - /** - * iterator position - */ - private int $position = 0; - /** * @inheritDoc */ @@ -70,83 +57,15 @@ class PageNode extends DatabaseObjectDecorator implements \Countable, \Recursive $this->children = $children; } - /** - * Returns the parent node - */ - public function getParentNode(): ?self - { - return $this->parentNode; - } - - /** - * Returns the number of children. - */ - public function count(): int - { - return \count($this->children); - } - - /** - * @inheritDoc - */ - public function rewind(): void - { - $this->position = 0; - } - - /** - * @inheritDoc - */ - public function valid(): bool - { - return isset($this->children[$this->position]); - } - - /** - * @inheritDoc - */ - public function next(): void - { - $this->position++; - } - - /** - * @inheritDoc - */ - public function current(): self - { - return $this->children[$this->position]; - } - - /** - * @inheritDoc - */ - public function key(): int - { - return $this->position; - } - - /** - * @inheritDoc - */ - public function getChildren(): self - { - return $this->children[$this->position]; - } - - /** - * @inheritDoc - */ - public function hasChildren(): bool + #[\Override] + public function getDepth(): int { - return \count($this->children) > 0; + return $this->depth; } - /** - * Returns node depth. - */ - public function getDepth(): int + #[\Override] + public function __toString(): string { - return $this->depth; + return $this->getDecoratedObject()->name; } }