first commit.

This commit is contained in:
kj
2026-10-05 15:08:39 -03:00
commit b7799f9fff
93 changed files with 8966 additions and 0 deletions
@@ -0,0 +1,64 @@
<?php
namespace Toolbox;
final class Component
{
/**
* @param list<string> $files
* @param array<string, string> $requires
* @param array<string, string>|null $destinations
*/
public function __construct(
public readonly string $name,
public readonly array $files,
public readonly array $requires = [],
public readonly ?string $coreRequires = null,
public readonly ?string $coreTested = null,
public readonly ?array $destinations = null,
public readonly bool $override = false,
) {
}
public static function fromArray(string $name, array $data): self
{
if (!isset($data['files']) || !is_array($data['files']) || $data['files'] === []) {
throw new ToolboxException("El componente '{$name}' debe declarar 'files' no vacío");
}
foreach ($data['files'] as $file) {
if (!is_string($file) || $file === '') {
throw new ToolboxException("El componente '{$name}' tiene un archivo inválido");
}
}
$requires = [];
foreach (($data['require'] ?? []) as $id => $constraint) {
if (!is_string($id) || !is_string($constraint)) {
throw new ToolboxException("El componente '{$name}' tiene un 'require' inválido");
}
$requires[$id] = $constraint;
}
$destinations = null;
if (isset($data['destinations'])) {
if (!is_array($data['destinations'])) {
throw new ToolboxException("El componente '{$name}' tiene 'destinations' inválido");
}
$destinations = [];
foreach ($data['destinations'] as $from => $to) {
$destinations[$from] = $to;
}
}
return new self(
name: $name,
files: array_values($data['files']),
requires: $requires,
coreRequires: $data['core']['requires'] ?? null,
coreTested: $data['core']['tested'] ?? null,
destinations: $destinations,
override: (bool) ($data['override'] ?? false),
);
}
}