Skip to content

Commit

Permalink
Merge pull request #18 from 4rthem/anonymous-group
Browse files Browse the repository at this point in the history
Group eligibility for anonymous users
  • Loading branch information
richardfullmer authored Aug 1, 2017
2 parents d804933 + 8972ebe commit 2e5a72b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
```
Expand Down
10 changes: 6 additions & 4 deletions src/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Rollout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2e5a72b

Please sign in to comment.