From 5a467ae38de2212e31fb2d881ae0a410053e35de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 25 Sep 2024 10:57:52 +0200 Subject: [PATCH] Add ChillUrlGenerator and ChillUrlGeneratorInterface Introduced a new interface ChillUrlGeneratorInterface for URL generation with return path handling. Implemented this interface in the ChillUrlGenerator class, which uses Symfony components to manage URL generation and request information. --- .../Routing/ChillUrlGenerator.php | 43 +++++++++++++++++++ .../Routing/ChillUrlGeneratorInterface.php | 35 +++++++++++++++ .../config/services/routing.yaml | 5 +++ 3 files changed, 83 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Routing/ChillUrlGenerator.php create mode 100644 src/Bundle/ChillMainBundle/Routing/ChillUrlGeneratorInterface.php diff --git a/src/Bundle/ChillMainBundle/Routing/ChillUrlGenerator.php b/src/Bundle/ChillMainBundle/Routing/ChillUrlGenerator.php new file mode 100644 index 000000000..eaecee628 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Routing/ChillUrlGenerator.php @@ -0,0 +1,43 @@ +urlGenerator->generate($name, $parameters, $referenceType); + } + + public function generateWithReturnPath(string $name, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string + { + $uri = $this->requestStack->getCurrentRequest()->getRequestUri(); + + return $this->urlGenerator->generate($name, [$parameters, 'returnPath' => $uri], $referenceType); + } + + public function returnPathOr(string $name, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string + { + $request = $this->requestStack->getCurrentRequest(); + + if ($request->query->has('returnPath')) { + return $request->query->get('returnPath'); + } + + return $this->urlGenerator->generate($name, $parameters, $referenceType); + } +} diff --git a/src/Bundle/ChillMainBundle/Routing/ChillUrlGeneratorInterface.php b/src/Bundle/ChillMainBundle/Routing/ChillUrlGeneratorInterface.php new file mode 100644 index 000000000..5c00fa665 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Routing/ChillUrlGeneratorInterface.php @@ -0,0 +1,35 @@ +