summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Group.php34
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
{