*/ protected array $children; /** @var array, Route[]> */ protected array $routes = []; public function __construct( SpecialSegment|string $content, protected ?self $parent = null, ) { if ($content instanceof SpecialSegment) { $this->content = $content->value; $this->specialSegment = $content; } else { $this->content = $content; } } public function getContent(): string { return $this->content; } public function getParent(): ?self { return $this->parent; } /** @return self[] */ public function getAncestors(): array { $results = []; $count = 0; $instance = $this->parent; while ( null !== $instance && $count++ < self::MAX_ANCESTORY_DEPTH ) { $results[] = $instance; $instance = $instance->parent; } return array_reverse($results); } /** @return self[] */ public function getAncestorsAndSelf(): array { $results = $this->getAncestors(); $results[] = $this; return $results; } public function addChild(self $segment): void { $this->children[$segment->getContent()] = $segment; } /** @return array */ public function getChildren(): array { return $this->children; } public function addRoute(): void { } }