44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Toolbox;
|
|
|
|
/**
|
|
* Regla de destino: `src/**` -> ROOT_CORE (sin el prefijo `src/`); el resto ->
|
|
* ROOT_DIR. Admite un mapa explícito por componente.
|
|
*/
|
|
final class Destination
|
|
{
|
|
public static function resolve(
|
|
string $source,
|
|
string $rootDir,
|
|
string $rootCore,
|
|
?array $explicit = null
|
|
): string {
|
|
$target = self::relative($source, $rootDir, $rootCore, $explicit);
|
|
|
|
return rtrim($rootDir, '/') . '/' . $target;
|
|
}
|
|
|
|
public static function relative(
|
|
string $source,
|
|
string $rootDir,
|
|
string $rootCore,
|
|
?array $explicit = null
|
|
): string {
|
|
if ($explicit !== null && isset($explicit[$source])) {
|
|
return ltrim($explicit[$source], '/');
|
|
}
|
|
|
|
$source = ltrim($source, '/');
|
|
|
|
if (str_starts_with($source, 'src/')) {
|
|
$inCore = substr($source, 4);
|
|
$prefix = rtrim(str_replace(rtrim($rootDir, '/') . '/', '', $rootCore), '/');
|
|
|
|
return ($prefix === '' ? '' : $prefix . '/') . $inCore;
|
|
}
|
|
|
|
return $source;
|
|
}
|
|
}
|