- How do I integrate Input Manager Bundle into a Laravel project that doesn’t use Symfony?
- Install the required Symfony bridge packages (`symfony/validator`, `symfony/translation`) via Composer, then register the `InputManager` as a Laravel service provider. The package works with Laravel’s native `Request` object by converting it to JSON/array before deserialization, so no deep Symfony dependency is mandatory.
- Can I use this package for Eloquent models instead of Doctrine entities?
- Yes, but you’ll need to adapt the `EntityFromId` attribute or custom logic to fetch Eloquent models by ID. The core deserialization and validation workflow remains the same, as the package focuses on input transformation rather than ORM-specific operations.
- What’s the performance impact of using Input Manager for high-traffic APIs (e.g., 10K+ RPS)?
- The package adds overhead due to deserialization, validation, and mapping layers. For high-throughput APIs, benchmark your payload size and complexity—deeply nested or large JSON (>1MB) may cause latency. Consider caching validated inputs or optimizing validator constraints.
- How does this compare to Laravel’s built-in Form Request validation?
- Input Manager Bundle offers more granular control over input transformation (e.g., nested objects, type conversion) and integrates with Symfony’s validation system, which is stricter for complex rules. Form Requests are simpler for basic validation but lack the DTO pattern and custom modifiers.
- Is there built-in support for API resource serialization/deserialization like API Platform?
- No, this package focuses on deserializing input into DTOs and mapping them to entities, not serializing entities back to API responses. You’d need to pair it with Laravel’s `Resource` classes or a separate serialization library for API output.
- How do I handle custom validation logic beyond Symfony’s constraints?
- Use the `ExtendedValidator` to create custom validators by implementing the `ValidatorInterface`. This allows you to inject business logic (e.g., checking database uniqueness) while keeping validation decoupled from your controllers or services.
- Will this work with Laravel 10+ and the latest Symfony components?
- The package is designed to work with Laravel’s Symfony bridge packages, which are regularly updated. Ensure you’re using compatible versions of `symfony/validator` and `symfony/translation` (e.g., ^6.0 for Laravel 10). Check the package’s `composer.json` for explicit version requirements.
- How do I mock InputManager and validators in PHPUnit tests?
- Mock the `InputManager` interface directly in your tests, focusing on its public methods like `deserialize()`, `validate()`, and `map()`. For validators, mock the `ValidatorInterface` or use Laravel’s `Validator` facade if you’re mixing validation systems.
- Can I use this for non-API use cases, like CLI commands or form submissions?
- Yes, the package is agnostic to the input source. For CLI commands, pass an array or JSON string to the deserializer. For forms, convert the submitted data (e.g., `$request->all()`) into an array before processing, though you’ll need to handle file uploads separately.
- What’s the best way to handle errors and translate validation messages in Laravel?
- Use Laravel’s built-in localization system for error messages by extending the `TranslatableMessage` class or integrating Symfony’s translator. For production, ensure your translation files (e.g., `resources/lang/en/validation.php`) include all custom validator messages.