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.
Request object parsing (e.g., $request->query->get()) with type-safe controller signatures using #[FromRoute], #[FromQuery], and #[FromBody]. Example: Validate pagination params (int<1,100> $limit) directly in method signatures.User object with non-empty-string email validation.positive-int for --limit flags.null for required fields or validate DateTime ranges.User::fromArray($legacyData)).list<City>).json_decode() + isset() checks.non-empty-string).ParamConverter, Laravel’s Form Requests) and you don’t want abstraction overhead.json_decode() may suffice.Problem:
"Our APIs and internal tools spend cycles manually parsing and validating data, leading to bugs in production (e.g., invalid user inputs, malformed payloads). This increases support costs and slows down feature delivery."
Solution:
"Valinor is a lightweight, dependency-free library that automates data mapping and validation using PHP’s native type system. It turns raw inputs (JSON, HTTP requests, CLI args) into type-safe objects with clear error messages—reducing bugs by 30–50% and cutting dev time by 20% on new endpoints. Used by teams at [Company X] to enforce API contracts without writing custom parsers."
ROI:
Ask:
"Should we allocate 2 sprints to integrate Valinor for our API layer and CLI tools, targeting a 20% reduction in data-related bugs?"
Why Valinor?
"This is PHP’s answer to Rust’s
serdeor Python’spydantic—but for HTTP requests, JSON, and nested data. Key benefits:"
Type Safety Without Compromises:
non-empty-string, int<1,100>, list<City>, and more at runtime.HTTP Request Superpowers:
public function createUser(
#[FromBody] UserDto $user, // Auto-validates JSON body
#[FromQuery] int $page = 1 // Validates query params
) { ... }
$request->query->get() or $request->request->all().Performance:
Flexibility:
Migration Path:
#[FromRoute/Query/Body] attributes.Alternatives Compared:
| Feature | Valinor | Symfony Validator | Laravel Form Requests | Custom Code |
|---|---|---|---|---|
| Type Safety | ✅ (PHP 8+ types) | ❌ (Basic) | ❌ (Basic) | ❌ |
| HTTP Requests | ✅ (Route/Query/Body) | ❌ (Manual) | ✅ (Limited) | ❌ |
| Nested Validation | ✅ (Arrays/Objects) | ✅ | ❌ | ❌ |
| Performance | ✅ (Optimized) | ❌ (Heavy) | ❌ (Framework-coupled) | ❌ |
| Dependency-Free | ✅ | ❌ (Symfony) | ❌ (Laravel) | ✅ |
Proposal:
"Let’s pilot Valinor for our
/usersAPI and CLI migration tool. If it reduces validation bugs by 30% in 2 weeks, we’ll expand it to all new endpoints. The learning curve is low—similar to Symfony’s attributes but more powerful."
How can I help you explore Laravel packages today?