| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
⭐ Found this useful? Install from Packagist · Give it a star on GitHub so more developers can find it.
Controller Kit Bundle — Utilities for Symfony controllers: redirectToReferer (configurable default route) and SafeForwardTrait for safe request forwarding. Tested on Symfony 7.4, 8.0, and 8.1 (also compatible with Symfony 7.0–7.3) · PHP 8.2+ (Symfony 8.x requires PHP 8.4+).
This bundle is FrankenPHP worker mode friendly.
composer require nowo-tech/controller-kit-bundleWith Symfony Flex, the recipe registers the bundle and adds config. Without Flex, see docs/INSTALLATION.md.
Manual registration in config/bundles.php:
return [
// ...
Nowo\ControllerKitBundle\NowoControllerKitBundle::class => ['all' => true],
];In config/packages/nowo_controller_kit.yaml:
nowo_controller_kit:
default_route: homepage # Route used when redirectToReferer has no valid RefererUse your own route name (e.g. app_home, dashboard).
Use the trait in a controller that extends AbstractController:
use Nowo\ControllerKitBundle\Controller\RedirectToRefererTrait;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
class MyController extends AbstractController
{
use RedirectToRefererTrait;
public function submit(Request $request): Response
{
// ... handle form ...
return $this->redirectToReferer($request);
// Optional: merge params and set status
// return $this->redirectToReferer($request, ['success' => 1], 303);
}
}When the request has a valid Referer header (same host as the current request, path matches a route in your app), the user is redirected there (with path and query params preserved). Otherwise they are redirected to the configured default_route.
Use the trait in any controller that has forward() (e.g. AbstractController):
use Nowo\ControllerKitBundle\Controller\SafeForwardTrait;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ApiController extends AbstractController
{
use SafeForwardTrait;
public function delegate(): Response
{
return $this->safeForward(
OtherController::class,
'actionName',
['id' => 123],
['page' => 1]
);
}
}If OtherController::actionName does not exist, a BadMethodCallException is thrown instead of a generic error.
The demo runs FrankenPHP + Caddy in Docker with APP_ENV=dev. Runtime mode is FRANKENPHP_MODE (worker default, or classic for per-request PHP) — see docs/DEMO-FRANKENPHP.md.
Global demo commands: make -C demo help (e.g. make -C demo up-symfony8).
make up
make install
make test
make cs-check
make phpstan
make release-checkMIT · Nowo.tech · Héctor Franco Aceituno
| Back | FazBrowse Home | New Git URL |