Skip to content

Commit

Permalink
Fix issue with accessing request in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
benr77 committed May 12, 2023
1 parent 14ec73b commit 45fb080
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Toggle/Conditions/Percentage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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']);
Expand Down

0 comments on commit 45fb080

Please sign in to comment.