From ba9dfd0230ac5ea9c16e5a4c9f8b43669cce4b51 Mon Sep 17 00:00:00 2001 From: Ben Walch Date: Fri, 6 Oct 2023 17:15:42 +0200 Subject: [PATCH] fix tests --- src/Adapter/Redirector/AbstractRedirector.php | 6 ++++-- src/Adapter/Redirector/CookieRedirector.php | 10 +++------- .../Compiler/RedirectorAdapterPass.php | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Adapter/Redirector/AbstractRedirector.php b/src/Adapter/Redirector/AbstractRedirector.php index 15bda61..291c9ad 100644 --- a/src/Adapter/Redirector/AbstractRedirector.php +++ b/src/Adapter/Redirector/AbstractRedirector.php @@ -29,8 +29,10 @@ public function getConfig(): array public function setConfig(array $config): void { $configResolver = $this->getConfigResolver(); - if (null === $configResolver && !empty($config)) { - throw new \Exception(sprintf('redirector adapter "%s" has a config, but no config resolver was provided.', $this->getName())); + if (null === $configResolver) { + if (!empty($config)) { + throw new \Exception(sprintf('redirector adapter "%s" has a config, but no config resolver was provided.', $this->getName())); + } } else { $this->config = $configResolver->resolve($config); } diff --git a/src/Adapter/Redirector/CookieRedirector.php b/src/Adapter/Redirector/CookieRedirector.php index ae08713..f1a3d51 100644 --- a/src/Adapter/Redirector/CookieRedirector.php +++ b/src/Adapter/Redirector/CookieRedirector.php @@ -8,15 +8,11 @@ class CookieRedirector extends AbstractRedirector { - protected CookieHelper $cookieHelper; - - public function __construct() - { - $this->cookieHelper = new CookieHelper($this->config['cookie']); - } public function makeDecision(RedirectorBag $redirectorBag): void { + $cookieHelper = new CookieHelper($this->config['cookie']); + if ($this->lastRedirectorWasSuccessful($redirectorBag) === true) { return; } @@ -28,7 +24,7 @@ public function makeDecision(RedirectorBag $redirectorBag): void $language = null; $request = $redirectorBag->getRequest(); - $redirectCookie = $this->cookieHelper->get($request); + $redirectCookie = $cookieHelper->get($request); //if no cookie available the validation fails. if (is_array($redirectCookie) && !empty($redirectCookie['url'])) { diff --git a/src/DependencyInjection/Compiler/RedirectorAdapterPass.php b/src/DependencyInjection/Compiler/RedirectorAdapterPass.php index 24b62af..a7ff5e7 100644 --- a/src/DependencyInjection/Compiler/RedirectorAdapterPass.php +++ b/src/DependencyInjection/Compiler/RedirectorAdapterPass.php @@ -15,7 +15,7 @@ public function process(ContainerBuilder $container): void $definition = $container->getDefinition(RedirectorRegistry::class); $registry = $container->getParameter('i18n.registry'); - $redirectorRegistry = $registry['redirector'] ?? []; + $redirectorRegistry = $registry['redirector']; foreach ($container->findTaggedServiceIds('i18n.adapter.redirector', true) as $serviceId => $attributes) { $priority = $attributes[0]['priority'] ?? 0;