add element siblings

This commit is contained in:
Yisroel Baum 2026-06-21 22:37:33 +03:00
parent eb868679c8
commit 96774d9540
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 47 additions and 9 deletions

View file

@ -27,10 +27,19 @@ class GetElement
throw new NotFoundException('Element not found');
}
$parentElement = $element->getParentElement();
if ($parentElement === null) {
$siblingElements = [$element];
} else {
$siblingElements = $this->elementRepository
->findByParentElement($parentElement);
}
return new GetElementResult(
element: $element,
childElements: $this->elementRepository
->findByParentElement($element),
siblingElements: $siblingElements,
);
}
}

View file

@ -8,10 +8,12 @@ class GetElementResult
{
/**
* @param Element[] $childElements
* @param Element[] $siblingElements
*/
public function __construct(
private Element $element,
private array $childElements,
private array $siblingElements,
) {
}
@ -27,4 +29,12 @@ class GetElementResult
{
return $this->childElements;
}
/**
* @return Element[]
*/
public function getSiblingElements(): array
{
return $this->siblingElements;
}
}