This package introduces attribute-based HTTP request mapping (route/query/body) with Valinor’s advanced type system, aligning well with modern Laravel/Symfony architectures. It replaces manual parsing (e.g., $request->query->get()) with declarative, type-safe argument injection, reducing boilerplate and improving maintainability. The integration with Symfony’s #[AsController] and #[Route] attributes ensures seamless adoption in API-heavy applications.
Key strengths:
non-empty-string, int<10,100>) and custom validation.422 Unprocessable Entity responses with detailed validation messages.MapRequestAttribute allows team-specific defaults (e.g., snake_case enforcement).Trade-offs:
#[MapQueryString]/#[MapRequestPayload] (Symfony 6.3+) offers similar functionality but lacks Valinor’s advanced features (e.g., int<min,max>).High for Laravel/Symfony applications with:
Challenges:
$_GET, $request->request->all()) would require refactoring.$request objects may need updates to mock mapped arguments.| Risk Area | Severity | Mitigation |
|---|---|---|
| Breaking changes | Low | Backward-compatible (new features only; no deprecated methods in 2.3.0). |
| Performance regression | Medium | Profile critical endpoints; cache mapper builders if reused. |
| Validation edge cases | Medium | Test with malformed input (e.g., null values, nested objects). |
| Symfony version lock | Low | Works with Symfony 5.4+ (Laravel 9+ via Symfony bridge). |
| Custom attribute conflicts | Low | Namespacing (e.g., App\Attribute\MapRequest) avoids collisions. |
Adoption Scope:
Type Safety:
non-empty-string, int<min,max>) justified for all endpoints, or only critical ones?positive-int) to reduce complexity?Error Handling:
HttpRequestMappingError be logged vs. surfaced to clients (e.g., API docs)?Performance:
Tooling:
#[FromQuery]) be documented for the team?MyAppMapRequest) be version-controlled or auto-generated?Primary Use Case: Laravel/Symfony APIs with:
Secondary Use Case: Legacy systems migrating from manual parsing to structured validation.
Compatibility:
| Phase | Action | Tools/Examples |
|---|---|---|
| Assessment | Audit 10% of endpoints for manual parsing complexity. | Search for ->query->get(), $_GET, $request->request->all(). |
| Pilot | Refactor 1–2 high-value endpoints (e.g., /api/users?page=X&limit=X). |
Use #[MapRequest] + #[FromQuery] for pagination. |
| Standardization | Define team defaults (e.g., snake_case keys, 422 errors). |
Create App\Attribute\ApiMapRequest with shared configurators. |
| Full Rollout | Replace manual parsing in remaining endpoints. | Use mapAll: true for complex DTOs (e.g., filters). |
| Deprecation | Phase out legacy parsing (e.g., mark with @deprecated in PRs). |
Use #[FromQuery] + #[FromBody] for new code. |
#[MapQueryString] may reduce need for Valinor in simple cases.$request before mapping (e.g., JSON parsing).#[MapRequest(ignoreMissing: true)] to avoid breaking existing optional params.#[FromRoute] string $id).$request->query->get() calls.positive-int) vs. scattered in controllers.422 responses with machine-readable messages.HttpRequestMappingError may require familiarity with Valinor.Mitigations:
snake_case keys").#[ApiMapRequest]) to enforce consistency."abc" for positive-int → clear error messages help.camelCase vs. snake_case → enforce via RestrictKeysToSnakeCase.#[FromQuery], #[FromBody] for autocomplete.MapperBuilder instances for reused configurations.422 errors may increase logging volume.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Invalid request data | 422 errors flood logs. |
Rate-limit logging; use structured logging (e.g., ELK). |
How can I help you explore Laravel packages today?