phpro/api-problem-bundle
Symfony bundle that turns exceptions into RFC7807 Problem Details responses (application/problem+json). Listens for ApiProblemException/HttpException/Security exceptions and converts them to standardized JSON errors based on phpro/api-problem, with support for custom transformers.
App\Exceptions\Handler can still intercept exceptions and format them into RFC7807 responses.Illuminate\Validation, Eloquent). The XML config removal does not affect these areas.symfony/http-foundation, symfony/validator). The XML config removal reduces one potential integration hurdle but does not address core dependency gaps.config/app.php) integrate with it?Extension classes or can it use Laravel’s register()/boot() methods?FormRequest validation to Problem details.sanctum/passport remains a manual effort.__() is still a gap.App\Exceptions\Handler and middleware for RFC7807 responses.ProblemResponseMiddleware) is still the primary integration point.Illuminate\Validation\Validator for Problem details.ProblemType definitions).config/packages/api_problem.yaml).ProblemServiceProvider or if Laravel’s config/app.php can register its services.Problem class and ProblemException to Laravel.ProblemType definitions, migrate these to:
app/Problem/ValidationProblem.php).config/api_problem.php).// app/Http/Middleware/ProblemResponse.php
public function handle($request, Closure $next) {
try {
return $next($request);
} catch (ProblemException $e) {
return response()->json($e->getProblem(), $e->getStatusCode());
}
}
ConstraintViolationListProblem) are still needed.ProblemType, ensure they can be autoloaded by Laravel’s Composer autoloader.config/packages/).ProblemType classes are discoverable).ProblemType definitions are now loaded (PHP classes? Config files?).Problem details to reduce payload size.| Scenario | Impact | Mitigation |
|---|---|---|
| Malformed Problem JSON | Clients may reject responses. | Validate output with json_schema. |
| Missing Extensions | Clients ignore unknown fields. | Use ext field for custom data. |
| Validation Overhead | Slow responses for complex rules. | Cache validation errors. |
| Middleware Conflicts | Order-dependent behavior. | Test middleware priority. |
| New Risk: Config Misload | If ProblemType classes are not autoloaded, errors may fail silently. |
Ensure PHP classes are in composer.json autoload or use Laravel’s config/app.php bindings. |
### Configuring Problem Types in Laravel
Instead of XML, define custom `ProblemType` classes in PHP:
```php
// app/Problem/CustomProblem.php
namespace App\Problem;
use PhpOption\Problem\Problem;
class CustomProblem extends Problem {}
Register them in AppServiceProvider@boot():
Problem::addType('custom', CustomProblem::class);
How can I help you explore Laravel packages today?