v0.9.4
This commit is contained in:
commit
217b733bf2
286 files changed
+19180
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Statistics;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* What a page is called on the statistics and numbers screens, when it has no title of its own (a post has). The address is the fallback.
|
||||
* A site names its pages in `manager.statistics.names` (`'/over-ons' => 'About us'`), and a kind of page with many of them (a service,
|
||||
* a project) with a resolver: `app(PageNames::class)->register(fn (string $path) => ...)` returns the name, or null for "not mine".
|
||||
*/
|
||||
final class PageNames
|
||||
{
|
||||
/** @var list<Closure(string): ?string> */
|
||||
private array $resolvers = [];
|
||||
|
||||
/** @param Closure(string): ?string $resolver gets an address like `/over-ons` */
|
||||
public function register(Closure $resolver): void
|
||||
{
|
||||
$this->resolvers[] = $resolver;
|
||||
}
|
||||
|
||||
public function name(string $path): ?string
|
||||
{
|
||||
$names = (array) config('manager.statistics.names', []);
|
||||
$name = $names[$path] ?? $names['/'.trim($path, '/')] ?? null;
|
||||
|
||||
if (is_string($name) && $name !== '') {
|
||||
return $name;
|
||||
}
|
||||
|
||||
foreach ($this->resolvers as $resolver) {
|
||||
$name = $resolver($path);
|
||||
|
||||
if (is_string($name) && $name !== '') {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user