From 45fb0808a0ef32f61ce00f353699831c647d43ad Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Fri, 12 May 2023 12:17:05 +0200 Subject: [PATCH] Fix issue with accessing request in constructor --- Toggle/Conditions/Percentage.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Toggle/Conditions/Percentage.php b/Toggle/Conditions/Percentage.php index 7d0f093..f8da3e1 100644 --- a/Toggle/Conditions/Percentage.php +++ b/Toggle/Conditions/Percentage.php @@ -14,11 +14,11 @@ class Percentage extends AbstractCondition implements ConditionInterface const BASIC_LIFETIME = 86400; - private Request $request; + private RequestStack $requestStack; - public function __construct(RequestStack $request) + public function __construct(RequestStack $requestStack) { - $this->request = $request->getMainRequest(); + $this->requestStack = $requestStack; } /** @@ -31,8 +31,8 @@ public function validate($config, $argument = null) { $config = $this->formatConfig($config); - if ($this->request->cookies->has($config['cookie'])) { - return (bool)$this->request->cookies->get($config['cookie']); + if ($this->requestStack->getMainRequest()->cookies->has($config['cookie'])) { + return (bool)$this->requestStack->getMainRequest()->cookies->get($config['cookie']); } $value = (int)($this->generateRandomNumber() < $config['percentage']);