diff options
| author | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
| commit | 11cb664b7a1956ec18227088be08b098a1a14865 (patch) | |
| tree | ef83419e41dee549db9bae47a3e4aa6f530f3b1c /src/Group.php | |
| parent | a61bcc830dfe801db7f94e01bbbe5a0b7b0a7dea (diff) | |
made and tested getFullPath and written getFullName.
Diffstat (limited to 'src/Group.php')
| -rw-r--r-- | src/Group.php | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/Group.php b/src/Group.php index c208180..9f08d25 100644 --- a/src/Group.php +++ b/src/Group.php @@ -38,18 +38,27 @@ class Group return $this->prefix; } - public function getPath(): string + /** + * @param callable(Group): ?string $getter + * + * @return string[] + */ + private function getAncestorString(callable $getter): array { $ancestors = $this->getAncestorsAndSelf(); - return '/' . implode('/', array_filter( - array_map(fn(Group $g): ?string => ( - ($v = $g->getPrefix()) === null ? - null : - trim($v, '/') - ), $ancestors), - fn (?string $v) => $v !== null - )); + 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 '/'.implode('/', $prefixes); } public function name(string $value): static @@ -64,6 +73,13 @@ class Group 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 { |
