Skip to content

Commit

Permalink
rename public_url_override to url_override
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloJoan committed Oct 29, 2018
1 parent a4b2634 commit 94e3bbb
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 69 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ For full documentation, check [the wiki page](https://github.com/PabloJoan/featu
* * * [$config_array['features']['feature_name']['sources']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_namesources)
* * * [$config_array['features']['feature_name']['admin']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_nameadmin)
* * * [$config_array['features']['feature_name']['internal']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_nameinternal)
* * * [$config_array['features']['feature_name']['public_url_override']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_namepublic_url_override)
* * * [$config_array['features']['feature_name']['url_override']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_nameurl_override)
* * * [$config_array['features']['feature_name']['bucketing']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_namebucketing)
* * * [$config_array['features']['feature_name']['exclude_from']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_nameexclude_from)
* * * [$config_array['features']['feature_name']['start']](https://github.com/PabloJoan/feature/wiki/Config-API#config_arrayfeaturesfeature_namestart)
Expand Down Expand Up @@ -263,7 +263,7 @@ cases along with the most concise way to write the configuration.
```php
$server_config['features']['foo'] = [
'enabled' => 0,
'public_url_override' => true
'url_override' => true
];
```
## Configuration details
Expand Down Expand Up @@ -305,7 +305,7 @@ They can enable a variant of a feature if no `'enabled'` value is provided or
if the variant’s percentage is 0.

The two remaining feature config properties are `'bucketing'` and
`'public_url_override'`. Bucketing specifies how users are bucketed when a
`'url_override'`. Bucketing specifies how users are bucketed when a
feature is enabled for only a percentage of users. The default value,
`'random'`, causes each request to be bucketed independently meaning that the
same user will be in different buckets on different requests. This is typically
Expand All @@ -320,7 +320,7 @@ Finally the bucketing value, `'uaid'`, causes bucketing via the UAID cookie
which means a user will be in the same bucket regardless of whether they are
signed in or not.

The `'public_url_override'` property allows all requests, not just admin and
The `'url_override'` property allows all requests, not just admin and
internal requests, to turn on a feature and choose a variant via the `features`
query param. Its value will almost always be true if it is present since it
defaults to false if omitted.
Expand All @@ -329,7 +329,7 @@ defaults to false if omitted.

The precedence of the various mechanisms for enabling a feature are as follows.

- If `'public_url_override'` is true and the request contains a `features` query
- If `'url_override'` is true and the request contains a `features` query
param that specifies a variant for the feature in question, that variant is
used. The value of the `features` param is a comma-delimited list of
features where each feature is either simply the name of the feature,
Expand Down
32 changes: 16 additions & 16 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Config

function __construct (User $user, Url $url, string $source)
{
$this->user = $user;
$this->url = $url;
$this->user = $user;
$this->url = $url;
$this->source = $source;
}

Expand Down Expand Up @@ -74,27 +74,27 @@ function variantBucketingBy (Feature $feature, string $id) : string
*/
private function chooseVariant (Feature $feature, string $id) : string
{
return $this->variantFromURL($feature) ?:
$this->variantTime($feature) ?:
$this->variantExcludedFrom($feature) ?:
$this->variantForUser($feature) ?:
$this->variantForGroup($feature) ?:
$this->variantForSource($feature) ?:
$this->variantForInternal($feature) ?:
$this->variantForAdmin($feature) ?:
$this->variantByPercentage($feature, $id) ?:
return $this->variantFromURL ($feature) ?:
$this->variantTime ($feature) ?:
$this->variantExcludedFrom ($feature) ?:
$this->variantForUser ($feature) ?:
$this->variantForGroup ($feature) ?:
$this->variantForSource ($feature) ?:
$this->variantForInternal ($feature) ?:
$this->variantForAdmin ($feature) ?:
$this->variantByPercentage ($feature, $id) ?:
Variant::OFF;
}

/**
* If the feature has public_url_override set to true, a specific variant
* If the feature has url_override set to true, a specific variant
* can be specified in the 'features' query parameter. In all other cases
* return nothing, meaning nothing was specified. Note that foo:off will
* turn off the 'foo' feature.
*/
private function variantFromURL (Feature $feature) : string
{
return $feature->publicUrlOverride()->variant(
return $feature->urlOverride()->variant(
$feature->name(),
$this->url
);
Expand Down Expand Up @@ -185,7 +185,7 @@ private function randomish (Feature $feature, string $id) : float
$x = random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX;

default:
$x = $this->numberFromHash($feature, $id);
$x = $this->numberFromHash($feature->name() . "-$id");
}

return $x * 100;
Expand All @@ -195,9 +195,9 @@ private function randomish (Feature $feature, string $id) : float
* Map a hex value to the half-open interval between 0 and 1 while
* preserving uniformity of the input distribution.
*/
private function numberFromHash (Feature $feature, string $id) : float
private function numberFromHash (string $strToHash) : float
{
$hash = hash('haval192,3', $feature->name() . "-$id");
$hash = hash('haval192,3', $strToHash);
$x = 0;
for ($i = 0; $i < 47; ++$i) {
$x = ($x * 2) + (hexdec($hash[$i]) < 8 ? 0 : 1);
Expand Down
6 changes: 3 additions & 3 deletions src/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Feature
function __construct (array $input = null)
{
$this->features = new FeatureCollection($input['features'] ?? []);
$this->user = new User($input['user'] ?? []);
$this->url = new Url($input['url'] ?? '');
$this->source = $input['source'] ?? '';
$this->user = new User($input['user'] ?? []);
$this->url = new Url($input['url'] ?? '');
$this->source = $input['source'] ?? '';
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Value/ExcludeFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ function __construct (array $excludeFrom)
$countries = isset($excludeFrom['countries']);
$countries = $countries && \is_array($excludeFrom['countries']);

$this->zips = $zips ? $excludeFrom['zips'] : [];
$this->regions = $regions ? $excludeFrom['regions'] : [];
$this->zips = $zips ? $excludeFrom['zips'] : [];
$this->regions = $regions ? $excludeFrom['regions'] : [];
$this->countries = $countries ? $excludeFrom['countries'] : [];
}

function variant (User $user) : string
{
$zips = \in_array($user->zipcode(), $this->zips, true);
$regions = \in_array($user->region(), $this->regions, true);
$zips = \in_array($user->zipcode(), $this->zips, true);
$regions = \in_array($user->region(), $this->regions, true);
$countries = \in_array($user->country(), $this->countries, true);

return $zips || $regions || $countries ? Variant::OFF : '';
Expand Down
50 changes: 25 additions & 25 deletions src/Value/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ class Feature
private $sources;
private $admin;
private $internal;
private $publicUrlOverride;
private $urlOverride;
private $excludeFrom;
private $time;
private $bucketing;

function __construct (string $name, array $feature)
{
$enabled = $feature['enabled'] ?? 0;
$description = $feature['description'] ?? '';
$users = $feature['users'] ?? [];
$groups = $feature['groups'] ?? [];
$sources = $feature['sources'] ?? [];
$admin = $feature['admin'] ?? '';
$internal = $feature['internal'] ?? '';
$publicUrlOverride = $feature['public_url_override'] ?? false;
$enabled = $feature['enabled'] ?? 0;
$users = $feature['users'] ?? [];
$groups = $feature['groups'] ?? [];
$sources = $feature['sources'] ?? [];
$excludeFrom = $feature['exclude_from'] ?? [];
$start = $feature['start'] ?? '';
$end = $feature['end'] ?? '';
$bucketing = $feature['bucketing'] ?? '';

$this->name = $name;
$this->enabled = new Enabled($enabled);
$description = $feature['description'] ?? '';
$admin = $feature['admin'] ?? '';
$internal = $feature['internal'] ?? '';
$start = $feature['start'] ?? '';
$end = $feature['end'] ?? '';
$bucketing = $feature['bucketing'] ?? '';
$urlOverride = $feature['url_override'] ?? false;

$this->name = $name;
$this->description = $description;
$this->users = new Users($users);
$this->groups = new Groups($groups);
$this->sources = new Sources($sources);
$this->admin = new Admin($admin);
$this->internal = new Internal($internal);
$this->publicUrlOverride = new PublicUrlOverride($publicUrlOverride);
$this->enabled = new Enabled($enabled);
$this->users = new Users($users);
$this->groups = new Groups($groups);
$this->sources = new Sources($sources);
$this->admin = new Admin($admin);
$this->internal = new Internal($internal);
$this->urlOverride = new UrlOverride($urlOverride);
$this->excludeFrom = new ExcludeFrom($excludeFrom);
$this->time = new Time($start, $end);
$this->bucketing = new Bucketing($bucketing);
$this->time = new Time($start, $end);
$this->bucketing = new Bucketing($bucketing);
}

function name () : string
Expand Down Expand Up @@ -92,9 +92,9 @@ function internal () : Internal
return $this->internal;
}

function publicUrlOverride () : PublicUrlOverride
function urlOverride () : UrlOverride
{
return $this->publicUrlOverride;
return $this->urlOverride;
}

function excludeFrom () : ExcludeFrom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PabloJoan\Feature\Value;

class PublicUrlOverride
class UrlOverride
{
private $on;

Expand Down
14 changes: 7 additions & 7 deletions src/Value/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class User

function __construct (array $user)
{
$this->uaid = $user['uaid'] ?? '';
$this->id = $user['id'] ?? '';
$this->group = $user['group'] ?? '';
$this->zipcode = $user['zipcode'] ?? '';
$this->region = $user['region'] ?? '';
$this->country = $user['country'] ?? '';
$this->isAdmin = $user['is-admin'] ?? false;
$this->uaid = $user['uaid'] ?? '';
$this->id = $user['id'] ?? '';
$this->group = $user['group'] ?? '';
$this->zipcode = $user['zipcode'] ?? '';
$this->region = $user['region'] ?? '';
$this->country = $user['country'] ?? '';
$this->isAdmin = $user['is-admin'] ?? false;
$this->internalIP = $user['internal-ip'] ?? false;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,17 @@ function testExcludeFrom ()
);
}

function testPublicUrlOverride ()
function testUrlOverride ()
{
$feature = new Feature([
'features' => [
'testFeature' => [
'enabled' => ['variant1' => 0, 'variant2' => 0],
'public_url_override' => true
'url_override' => true
],
'testFeature2' => [
'enabled' => ['variant3' => 0, 'variant4' => 0],
'public_url_override' => true
'url_override' => true
]
],
'url' => 'http://www.testurl.com/?feature=testFeature:variant1,testFeature2:variant4'
Expand Down
10 changes: 5 additions & 5 deletions tests/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function setUp ()
'sources' => ['test3' => 'source1', 'test4' => 'source2'],
'admin' => 'test3',
'internal' => 'test1',
'public_url_override' => true,
'url_override' => true,
'exclude_from' => [
'zips' => ['10014', '10023'],
'countries' => ['us', 'rd'],
Expand Down Expand Up @@ -194,7 +194,7 @@ function testSetFeature ()
'enabled' => ['test1' => 0, 'test4' => 0],
'users' => ['test1' => '2', 'test4' => '7'],
'sources' => ['test1' => 'source3'],
'public_url_override' => true
'url_override' => true
]
);
$this->assertEquals($this->feature->isEnabled('testFeature2'), false);
Expand All @@ -209,7 +209,7 @@ function testChangeUser ()
'enabled' => ['test1' => 0, 'test4' => 0],
'users' => ['test1' => '2', 'test4' => '7'],
'sources' => ['test1' => 'source3'],
'public_url_override' => true
'url_override' => true
]
);
$this->feature->changeUser(['id' => '2']);
Expand All @@ -225,7 +225,7 @@ function testChangeUrl ()
'enabled' => ['test1' => 0, 'test4' => 0],
'users' => ['test1' => '2', 'test4' => '7'],
'sources' => ['test1' => 'source3'],
'public_url_override' => true
'url_override' => true
]
);
$this->feature->changeUrl(
Expand All @@ -243,7 +243,7 @@ function testChangeSource ()
'enabled' => ['test1' => 0, 'test4' => 0],
'users' => ['test1' => '2', 'test4' => '7'],
'sources' => ['test1' => 'source3'],
'public_url_override' => true
'url_override' => true
]
);
$this->feature->changeSource('source3');
Expand Down

0 comments on commit 94e3bbb

Please sign in to comment.