zenstruck/controller-util
Symfony controller utilities that cut boilerplate: traits for entity lookups with automatic 404 handling, flash messages, redirects, form processing, and template rendering, keeping your controllers small, consistent, and focused on the action itself.
This is a small, archived Symfony 2-era utility package. Treat it as a legacy helper, not a foundation for new work.
AbstractController with JsonResponse/RedirectResponse instead. If you are maintaining a Symfony 2.x application, continue.README.md, then src/, then tests/. The README is the authoritative place for the exact helper names; tests/ shows the expected response status codes, headers, and bodies.composer.json compatibility. Confirm the PHP constraint and the symfony/http-foundation constraint before requiring it. Run composer why-not zenstruck/controller-util if installation fails.Controller class. The point of the package is to let you build responses in plain controller classes or services without pulling in the framework controller base.Typical usage shape (the exact class/method API is defined in src/ — verify before copying):
// In a controller or service that does not extend the framework base Controller
return $responseHelper->json(['status' => 'ok']);
The first win is usually replacing ad-hoc new JsonResponse(...) or new RedirectResponse(...) calls with one consistent helper.
$this->get(...) calls and inheriting from the framework base controller.ApiResponseFactory that delegates to the package and adds your conventions (envelope shape, error codes, cache headers). This makes later migration to native Symfony responses trivial.Content-Type in one place. This is the highest-value pattern for day-to-day use.new Response(..., 404) code, but keep user-facing messages in your application layer.ResponseFactoryInterface and bind it to the package implementation. Swapping to native Symfony response classes later becomes a one-line container change.symfony/http-foundation. Responses still depend on HttpFoundation classes.Content-Type: application/json and that redirects use the status code you expect. Do not assume the helper applies your application's standard headers.JsonResponse. Check how encoding failures are surfaced.getStatusCode(), headers->all(), and getContent() rather than relying on browser output. If the helper is a service, confirm registration with bin/console debug:container.AbstractController::json()/redirect() or direct JsonResponse/RedirectResponse usage covers nearly everything this package does, with ongoing support. Plan removal rather than long-term adoption.How can I help you explore Laravel packages today?