Created
June 23, 2014 16:11
-
-
Save mamchenkov/c9205f9330e5153408a5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* 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