feat(compat): declare core independence with core:"none" (INDEPENDENT status, block inheritance, no warning)

This commit is contained in:
kj
2026-10-06 14:12:36 -03:00
parent fc51133d92
commit 901968d0bd
9 changed files with 247 additions and 69 deletions
+42 -2
View File
@@ -18,6 +18,8 @@ final class Component
public readonly ?string $description = null,
public readonly ?array $destinations = null,
public readonly bool $override = false,
public readonly bool $coreDeclared = false,
public readonly ?bool $coreIndependent = null,
) {
}
@@ -61,15 +63,53 @@ final class Component
$description = $data['description'];
}
$coreDeclared = array_key_exists('core', $data);
$coreIndependent = null;
$coreRequires = null;
$coreTested = null;
if ($coreDeclared) {
[$coreRequires, $coreTested, $coreIndependent] = self::parseCore($data['core'], "el componente '{$name}'");
}
return new self(
name: $name,
files: array_values($data['files']),
requires: $requires,
coreRequires: $data['core']['requires'] ?? null,
coreTested: $data['core']['tested'] ?? null,
coreRequires: $coreRequires,
coreTested: $coreTested,
description: $description,
destinations: $destinations,
override: (bool) ($data['override'] ?? false),
coreDeclared: $coreDeclared,
coreIndependent: $coreIndependent,
);
}
/**
* Bloque `core`: objeto de rango ({requires?, tested?}) o la cadena
* "none" (independencia afirmativa, excluyente con el rango).
*
* @return array{0: ?string, 1: ?string, 2: ?bool}
*/
public static function parseCore(mixed $core, string $origin): array
{
if ($core === 'none') {
return [null, null, true];
}
if (!is_array($core)) {
throw new ToolboxException("{$origin} tiene un 'core' inválido");
}
$requires = $core['requires'] ?? null;
$tested = $core['tested'] ?? null;
foreach (['requires' => $requires, 'tested' => $tested] as $key => $value) {
if ($value !== null && !is_string($value)) {
throw new ToolboxException("{$origin} tiene un 'core.{$key}' inválido");
}
}
return [$requires, $tested, null];
}
}