Check for names the site already uses, and bring the docs up to 0.5.0
This commit is contained in:
1 parent
a921f14d85
commit
541d1ee690
8 files changed
+77
-8
No files matched your search
@@ -31,6 +31,7 @@ class DoctorCommand extends Command
|
||||
$this->checkUserModel($modules);
|
||||
$this->checkTables($modules);
|
||||
$this->checkRoutes();
|
||||
$this->checkNames();
|
||||
$this->checkModules($modules);
|
||||
|
||||
$failed = collect($this->checks)->contains('status', 'fail');
|
||||
@@ -127,6 +128,38 @@ class DoctorCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/** Route names or addresses of the site that the package would share with its own. */
|
||||
private function checkNames(): void
|
||||
{
|
||||
$prefix = Names::routePrefix();
|
||||
$path = trim((string) config('manager.path'), '/');
|
||||
$names = [];
|
||||
$foreign = [];
|
||||
|
||||
foreach (Route::getRoutes()->getRoutes() as $route) {
|
||||
$name = (string) $route->getName();
|
||||
$mine = $route->isFallback || ($route->getActionName() === 'Closure' && str_starts_with($name, $prefix)) || str_starts_with(ltrim($route->getActionName(), '\\'), 'IriksIT\\Manager\\');
|
||||
|
||||
if ($prefix !== '' && str_starts_with($name, $prefix) && $name !== $prefix) {
|
||||
$names[$name] = ($names[$name] ?? 0) + 1;
|
||||
}
|
||||
|
||||
if (! $mine && ($route->uri() === $path || str_starts_with($route->uri(), $path.'/'))) {
|
||||
$foreign[] = $route->uri();
|
||||
}
|
||||
}
|
||||
|
||||
$twice = array_keys(array_filter($names, fn (int $count) => $count > 1));
|
||||
|
||||
if ($twice !== []) {
|
||||
$this->add('names', 'warn', 'Route names used twice: '.implode(', ', array_slice($twice, 0, 5)).'. The site and the manager share them, and one of the two stops working.', "Set 'route_name' in config/manager.php to something the site does not use, for example 'cms'.");
|
||||
} elseif ($foreign !== []) {
|
||||
$this->add('names', 'warn', 'The site has routes under the address of the manager: '.implode(', ', array_slice($foreign, 0, 5)).'.', "Move them, or set 'path' in config/manager.php (MANAGER_PATH) to another address.");
|
||||
} else {
|
||||
$this->add('names', 'ok', 'No route name or address is shared with the site.');
|
||||
}
|
||||
}
|
||||
|
||||
private function checkModules(ModuleRegistry $modules): void
|
||||
{
|
||||
$active = array_keys($modules->active());
|
||||
|
||||
Reference in new issue
Block a user