cuyz/valinor
Valinor maps raw input (JSON/arrays) into fully typed PHP objects, validating along the way with clear, human-readable errors. Supports advanced types (PHPStan/Psalm), shaped arrays, generics, ranges, and can normalize objects back to JSON/CSV while preserving structure.
User, Order). Reduces boilerplate for manual type casting/validation.Resource classes may overlap here.cuyz/valinor). Minimal setup required beyond basic configuration (e.g., cache, builders).Illuminate\Http\Request). The HttpRequest adapter supports PSR-7, compatible with Laravel’s underlying stack.MapperBuilder/NormalizerBuilder as Laravel services (e.g., in AppServiceProvider). Shared instances improve performance via caching.FileSystemCache (or Redis/Memcached via custom adapters).bootstrap/cache generation).MappingError must be caught and translated to Laravel’s exception handling (e.g., HttpResponse for APIs). Consider wrapping in a custom exception class.__get/__set methods.array{key: type}) might conflict with Laravel’s Collection macros.Carbon instances).Validator facade) or augment it?MappingError be mapped to Laravel’s ValidationException or a custom API error format?FormRequest::rules() with type hints + Valinor.repositories package).json_decode() + assert checks with Valinor.CreateUserRequestDTO).laravel-valinor) to:
MapperBuilder as a singleton.public function handle(Request $request, Closure $next) {
$mapper = app(MapperBuilder::class)->mapper();
$request->merge([
'validated' => $mapper->map(YourDTO::class, $request->all())
]);
return $next($request);
}
DataProvider for edge cases).array{key: type}) may conflict with Laravel’s Collection macros. Use explicit type hints (e.g., array<int, Model>).DateTime with Carbon via custom type mappings.FileSystemCache with Laravel’s storage_path().spatie/array-to-object): Evaluate overlap/duplication.laravel-validator): Decide whether to replace or complement.json and ctype extensions (standard in Laravel).| Phase | Task | Dependencies |
|---|---|---|
| 1. Setup | Install Valinor, configure cache, add PHPStan/Psalm extensions. | Composer, Laravel service container. |
| 2. Core Mapping | Map 1–2 critical DTOs (e.g., API requests/responses). | Basic Valinor usage. |
| 3. Integration | Register MapperBuilder as a service, create middleware. |
Laravel service container. |
| 4. Validation | Replace Form Requests with Valinor + PHPStan. | Static analysis tools. |
| 5. Normalization | Use normalizers for API responses. | Valinor normalizer setup. |
| 6. Testing | Add unit/integration tests for mappings. | PHPUnit, Pest. |
| 7. Optimization | Warm cache, profile performance. | Production monitoring. |
Validator::make()).FileWatchingCache in dev).php artisan valinor:warmup --classes="App\\DTO\\*"
php artisan valinor:clear-cache
How can I help you explore Laravel packages today?