Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created September 5, 2011 15:27
Show Gist options
  • Save lukemorton/1195250 to your computer and use it in GitHub Desktop.
Save lukemorton/1195250 to your computer and use it in GitHub Desktop.
Feature Switching
<?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