middleware = $middleware; } public function getRouter(): Router { return $this->router; } public function getParent(): ?self { return $this->parent; } public function prefix(string $value): static { $this->prefix = $value; return $this; } public function getPrefix(): ?string { return $this->prefix; } /** * @param callable(Group): ?string $getter * * @return string[] */ private function getAncestorString(callable $getter): array { $ancestors = $this->getAncestorsAndSelf(); return array_filter( array_map(fn ($g) => $getter($g), $ancestors), fn (?string $v): bool => null !== $v ); } public function getFullPrefix(): string { $prefixes = $this->getAncestorString(fn ($g) => $g->getPrefix()); $prefixes = array_map(fn (string $p) => trim($p, '/'), $prefixes); return count($prefixes) > 0 ? '/'.implode('/', $prefixes) : ''; } public function name(string $value): static { $this->name = $value; return $this; } public function getName(): ?string { return $this->name; } public function getFullName(): ?string { $names = $this->getAncestorString(fn ($g) => $g->getName()); return 0 === count($names) ? null : implode('', $names); } /** @param callable(GroupDefinition): void $cb */ public function group(callable $cb): void { ($cb)(new GroupDefinition( $this )); } }