Created
September 5, 2011 15:27
-
-
Save lukemorton/1195250 to your computer and use it in GitHub Desktop.
Feature Switching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In bootstrap or something | |
$featureSwitch = new FeatureSwitch; | |
$featureSwitch->addCondition('environment', function ($kernel) | |
{ | |
return $kernel->getBootstrap()->getEnvironment(); | |
}); | |
$featureSwitch->addCondition('is_user_active', function ($kernel, $user) | |
{ | |
return $user->getLastActive() > time() - 3600; | |
}); | |
$featureSwitch->addCondition('asl', function ($kernel, $user) | |
{ | |
return array($user->getAge(), $user->getSex(), $user->getLocation()); | |
}); | |
$featureSwitch->addFeature('male_welcome', array( | |
array('environment', 'development'), | |
array('environment', 'staging'), | |
array('is_user_active', TRUE), | |
array('asl', array(21, 'male', 'England')), | |
)); | |
// In application logic | |
if ($featureSwitch->isEnabled('male_welcome', $kernel, $user)) | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment