Skip to content

Instantly share code, notes, and snippets.

@mamchenkov
Created June 23, 2014 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamchenkov/c9205f9330e5153408a5 to your computer and use it in GitHub Desktop.
Save mamchenkov/c9205f9330e5153408a5 to your computer and use it in GitHub Desktop.
<?php
/**
* Quick proof of concept for feature management
*/
class Feature {
/**
* This is where we keep the list of features
*/
protected $features;
/**
* Constructor
*
* @param array $features List of supported features
*/
public function __construct($features = array()) {
$this->features = $features;
}
public function enable($feature) {
if (in_array($feature, array_keys($this->features))) {
$this->features[$feature] = true;
}
}
public function disable($feature) {
if (in_array($feature, array_keys($this->features))) {
$this->features[$feature] = false;
}
}
public function status() {
return $this->features;
}
public function isEnabled($feature) {
$result = false;
if (in_array($feature, array_keys($this->features)) && $this->features[$feature]) {
$result = true;
}
return $result;
}
}
////////////////////////////////////////
$someFeatures = array(
'featureA' => true,
'featureB' => true,
'featureC' => false,
);
$feature = new Feature($someFeatures);
$feature->disable('featureA');
$feature->enable('featureC');
print_r($feature->status());
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment