Rename the top-level lib/ directory to core/ so the project root immediately communicates which code is core platform and which lives in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the Composer PSR-4 path mapping moves from lib/ to core/. Module-internal lib/ directories (modules/*/lib/) are untouched. Updated across the full stack: - composer.json PSR-4 mapping - bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php) - tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer) - 26 architecture contract tests - enforcement-policy, guard-catalog, quality-gates - all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/) - bin/qa-extended.sh search paths - .claude/settings.local.json permission paths Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner → Executor → Code Review (4 findings fixed) → Security Review → Acceptance Test → Finalizer) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
102 lines
2.2 KiB
PHP
102 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Http\Input;
|
|
|
|
final class FormErrors
|
|
{
|
|
/** @var array<string, array<int, string>> */
|
|
private array $errors = [];
|
|
|
|
public function add(string $field, string $message): self
|
|
{
|
|
$field = trim($field);
|
|
if ($field === '') {
|
|
$field = 'input';
|
|
}
|
|
|
|
$message = trim($message);
|
|
if ($message === '') {
|
|
return $this;
|
|
}
|
|
|
|
$this->errors[$field] ??= [];
|
|
$this->errors[$field][] = $message;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param array<int, string> $messages
|
|
*/
|
|
public function addMany(string $field, array $messages): self
|
|
{
|
|
foreach ($messages as $message) {
|
|
$this->add($field, (string) $message);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function addGlobal(string $message): self
|
|
{
|
|
return $this->add('input', $message);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, array<int, string>|string>|array<int, string>|self $errors
|
|
*/
|
|
public function merge(array|self $errors): self
|
|
{
|
|
if ($errors instanceof self) {
|
|
$errors = $errors->toArray();
|
|
}
|
|
|
|
if (array_is_list($errors)) {
|
|
foreach ($errors as $message) {
|
|
$this->addGlobal((string) $message);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
foreach ($errors as $field => $messages) {
|
|
if (is_array($messages)) {
|
|
$this->addMany((string) $field, array_values(array_map('strval', $messages)));
|
|
continue;
|
|
}
|
|
|
|
$this->add((string) $field, (string) $messages);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function hasAny(): bool
|
|
{
|
|
return $this->errors !== [];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, string>>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return $this->errors;
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public function toFlatList(): array
|
|
{
|
|
$flat = [];
|
|
foreach ($this->errors as $messages) {
|
|
foreach ($messages as $message) {
|
|
$flat[] = $message;
|
|
}
|
|
}
|
|
|
|
return $flat;
|
|
}
|
|
}
|