Add explcit aliases for open links

This commit is contained in:
2026-02-13 10:10:57 +01:00
parent 4dae370deb
commit 232802b0ce
4 changed files with 64 additions and 11 deletions

View File

@@ -99,10 +99,10 @@ class Path
}
/**
* Map a real filesystem path back to a configured alias, if available.
* Map a real filesystem path back to an open-service alias, if available.
*
* Example: root "/share/Datascape/" with alias "/Scape/" maps
* "/share/Datascape/some/folder" -> "/Scape/some/folder".
* "/share/Datascape/some/folder" -> "Scape>some/folder".
*
* If no alias matches, the input path is returned unchanged (except for
* normalization of slashes and dot-segments).
@@ -117,12 +117,17 @@ class Path
// normalize input for matching, but do not force a trailing slash
$normalized = static::cleanPath($path, false);
// collect root->alias mappings (avoid alias keys that reference the same config)
// collect root->alias mappings for open-service links
// (avoid alias keys that reference the same config)
$mappings = [];
foreach ($this->paths as $key => $info) {
if (!isset($info['root']) || $key !== $info['root']) continue;
if (empty($info['alias'])) continue;
$mappings[$info['root']] = $info['alias'];
$alias = $this->normalizeOpenAlias((string)$info['alias']);
if ($alias === '') continue;
$mappings[$info['root']] = $alias;
}
if ($mappings === []) return $normalized;
@@ -131,16 +136,34 @@ class Path
uksort($mappings, static fn($a, $b) => strlen($b) - strlen($a));
foreach ($mappings as $root => $alias) {
$rootNoTrailingSlash = rtrim($root, '/');
if (!str_starts_with($normalized, $root) && $normalized !== $rootNoTrailingSlash) continue;
$suffix = '';
if (str_starts_with($normalized, $root)) {
$suffix = substr($normalized, strlen($root));
$alias = static::cleanPath($alias, true);
return rtrim($alias, '/') . '/' . $suffix;
$suffix = (string)substr($normalized, strlen($root));
}
$suffix = ltrim($suffix, '/');
return $alias . '>' . $suffix;
}
return $normalized;
}
/**
* Convert legacy path-like aliases (e.g. /Scape/) to open aliases (Scape).
*
* @param string $alias
* @return string
*/
protected function normalizeOpenAlias($alias)
{
$alias = trim($alias);
$alias = trim($alias, '/\\');
return $alias;
}
/**
* Clean a path for better comparison
*