diff --git a/README.md b/README.md index 31024fd..0c6f36b 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,11 @@ $rollout->activateGroup('chat', 'all'); You may also want to define your own groups. We have one for caretakers: ```php -$rollout->defineGroup('caretakers', function(RolloutUserInterface $user) { +$rollout->defineGroup('caretakers', function(RolloutUserInterface $user = null) { + if (null === $user) { + return false; + } + return $user->isCaretaker(); // boolean }); ``` diff --git a/src/Feature.php b/src/Feature.php index 4e5c312..070803f 100644 --- a/src/Feature.php +++ b/src/Feature.php @@ -189,13 +189,15 @@ public function clear() public function isActive(Rollout $rollout, RolloutUserInterface $user = null, array $requestParameters = array()) { if (null == $user) { - return $this->isParamInRequestParams($requestParameters) || $this->percentage == 100; + return $this->isParamInRequestParams($requestParameters) + || $this->percentage == 100 + || $this->isInActiveGroup($rollout); } return $this->isParamInRequestParams($requestParameters) || $this->isUserInPercentage($user) || $this->isUserInActiveUsers($user) || - $this->isUserInActiveGroup($user, $rollout); + $this->isInActiveGroup($rollout, $user); } /** @@ -244,11 +246,11 @@ private function isUserInActiveUsers(RolloutUserInterface $user) } /** - * @param RolloutUserInterface $user * @param Rollout $rollout + * @param RolloutUserInterface|null $user * @return bool */ - private function isUserInActiveGroup(RolloutUserInterface $user, Rollout $rollout) + private function isInActiveGroup(Rollout $rollout, RolloutUserInterface $user = null) { foreach ($this->groups as $group) { if ($rollout->isActiveInGroup($group, $user)) { diff --git a/src/Rollout.php b/src/Rollout.php index ea4caba..8e61d39 100644 --- a/src/Rollout.php +++ b/src/Rollout.php @@ -183,10 +183,10 @@ public function deactivateRequestParam($feature) /** * @param string $group - * @param RolloutUserInterface $user + * @param RolloutUserInterface|null $user * @return bool */ - public function isActiveInGroup($group, RolloutUserInterface $user) + public function isActiveInGroup($group, RolloutUserInterface $user = null) { if (!isset($this->groups[$group])) { return false;