Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
richardfullmer committed Apr 4, 2014
0 parents commit e243284
Show file tree
Hide file tree
Showing 13 changed files with 1,084 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
phpunit.xml
/vendor/
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- hhvm

before_script:
- composer install -n

script:
- vendor/bin/phpunit
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 James Golick

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
rollout (for php)
=================

Feature flippers for PHP. A port of ruby's [rollout](https://github.com/FetLife/rollout).

Install It
----------

composer require opensoft/rollout

How it works
------------

Initialize a rollout object:

```php
use Opensoft\Rollout\Rollout;
use Opensoft\Rollout\Storage\ArrayStorage;

$rollout = new Rollout(new ArrayStorage());
```

Check if a feature is active for a particular user:

```php
$rollout->isActive('chat', $user); // returns true/false
```

Check if a feature is activated globally:

```php
$rollout->isActive('chat'); // returns true/false
```

Storage
-------

There are a number of different storage implementations for where the configuration for the rollout is stored.

* ArrayStorage - default storage, not persistent
* DoctrineCacheStorageAdapter - requires `doctrine/cache`

The storage implementation must implement the `Storage\StorageInterface`'s methods.

Groups
------

Rollout ships with one group by default: `all`, which does exactly what it sounds like.

You can activate the `all` group for chat features like this:

```php
$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) {
return $user->isCaretaker(); // boolean
});
```

You can activate multiple groups per feature.

Deactivate groups like this:

```php
$rollout->deactivateGroup('chat');
```

Specific Users
--------------

You may want to let a specific user into a beta test or something. If that user isn't part of an existing group, you can let them in specifically:

```php
$rollout->activateUser('chat', $user);
```

Deactivate them like this:

```php
$rollout->deactivateUser('chat', $user);
```

Rollout users must implement the `RolloutUserInterface`.

User Percentages
----------------

If you're rolling out a new feature, you may want to test the waters by slowly enabling it for a percentage of your users.

```php
$rollout->activatePercentage('chat', 20);
```

The algorithm for determining which users get let in is this:

```php
crc32($user->getRolloutIdentifier()) % 100 < $percentage
```

So, for 20%, users 0, 1, 10, 11, 20, 21, etc would be allowed in. Those users would remain in as the percentage increases.

Deactivate all percentages like this:

```php
$rollout->deactivatePercentage('chat');
```

**Note:** Activating a feature for 100% of users will also make it activate `globally`. This is like calling `$rollout->isActive()` without a user object.

Feature is Broken
-----------------

Deactivate everybody at once:

```php
$rollout->deactivate('chat');
```

You may wish to disable features programmatically if monitoring tools detect unusually high error rates for example.

Symfony2 Bundle
---------------

A Symfony2 bundle is available to integrate rollout into Symfony2 projects. It can be found at http://github.com/opensoft/OpensoftRolloutBundle.

Implementations in other languages
----------------------------------

* Ruby: http://github.com/FetLife/rollout
* Python: http://github.com/asenchi/proclaim

Copyright
---------

Copyright © 2010 James Golick, BitLove, Inc. See LICENSE for details.
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "opensoft/rollout",
"description": "Feature flippers for PHP",
"keywords": ["feature", "flag", "toggle", "rollout", "flipper"],
"license": "MIT",
"authors": [
{
"name": "Richard Fullmer",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.3"
},
"suggest": {
"doctrine/cache": "For use with the DoctrineCacheStorageAdapter"
},
"require-dev": {
"phpunit/phpunit": "*",
"doctrine/cache": "*"
},
"autoload": {
"psr-4": {
"Opensoft\\Rollout\\": "src/"
}
}
}
28 changes: 28 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "vendor/autoload.php" >

<testsuites>
<testsuite name="Rollout Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>

</phpunit>
Loading

0 comments on commit e243284

Please sign in to comment.