cuyz/valinor
Valinor maps raw inputs (JSON/arrays) into validated, strongly typed PHP objects. Supports advanced PHPStan/Psalm types (shaped arrays, generics, ranges), produces precise human-readable errors, and can normalize data back to formats like JSON or CSV.
readonly, non-empty-string, generics) for input validation in APIs, CLI tools, or microservices, reducing runtime errors.Illuminate/Validation, Symfony/Validator) for HTTP request mapping, simplifying dependency management.Adopt when:
non-empty-string, generics, readonly).json_decode() + isset() checks).Look elsewhere if:
Serializer or Laravel’s FormRequest) and migration isn’t a priority."Valinor is a lightweight, dependency-free library that turns raw input (JSON, HTTP requests, etc.) into strongly-typed PHP objects—like a compiler for your data. This reduces bugs by catching invalid inputs early (e.g., missing fields, wrong types) and cuts development time by eliminating manual validation code. For example, instead of writing 50 lines of if/else checks for API requests, we’d use type hints and annotations to auto-validate inputs. It’s especially valuable for APIs, microservices, and CLI tools where data integrity is critical. The MIT license and zero dependencies make it easy to adopt without vendor lock-in."
ROI:
*"Valinor solves two key pain points:
isset()/filter_var() checks for JSON/HTTP inputs.non-empty-string, generics) to enforce types at map-time, with clear error messages.Key features:
#[FromRoute] string $userId).Example:
// Before: Manual validation
$user = [
'name' => $_POST['name'] ?? '',
'age' => (int)($_POST['age'] ?? 0),
];
if (empty($user['name'])) throw new \InvalidArgumentException('Name required');
// After: Type-safe mapping
$user = (new MapperBuilder())
->mapper()
->map(User::class, Source::json($json));
Why now?
FormRequest for hybrid validation)."*Migration Path:
json_decode() + isset() checks with Valinor::map().#[FromRoute], #[FromQuery]) for controllers.How can I help you explore Laravel packages today?