Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769481
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Features.php b/app/Features.php
index f31d67a..9ceaa8d 100644
--- a/app/Features.php
+++ b/app/Features.php
@@ -1,56 +1,91 @@
<?php
namespace Nasqueron\Notifications;
use Config;
/**
* The features class offers a sugar syntax to check if a feature is enabled
* in the Config repository, at app.features.
*
* Features could be added to config/app.php to the features array.
*/
class Features {
+ ///
+ /// Feature information
+ ///
+
+ /**
+ * @param string $feature The feature to get the config key
+ * @return string The config key
+ */
+ private static function getFeatureConfigKey ($feature) {
+ return 'app.features.' . $feature;
+ }
+
/**
* Determines if the specified feature is enabled
*
* @param string $feature The feature to check in the config
* @return bool
*/
public static function isEnabled ($feature) {
- $key = 'app.features.' . $feature;
+ $key = self::getFeatureConfigKey($feature);
return Config::has($key) && (bool)Config::get($key);
}
+ /**
+ * Enables a feature in our current configuration instance
+ *
+ * @param string $feature The feature
+ */
+ public static function enable ($feature) {
+ $key = self::getFeatureConfigKey($feature);
+ Config::set($key, true);
+ }
+
+ /**
+ * Disables a feature in our current configuration instance
+ *
+ * @param string $feature The feature
+ */
+ public static function disable ($feature) {
+ $key = self::getFeatureConfigKey($feature);
+ Config::set($key, false);
+ }
+
+ ///
+ /// Features lists
+ ///
+
/**
* Gets all the features, with the toggle status
*
* @return array An array with features as keys, bool as values (true if enabled)
*/
public static function getAll () {
return Config::get('app.features');
}
/**
* Lists all the features
*
* @return string[] a list of all features
*/
public static function getAvailable () {
$features = self::getAll();
return array_keys($features);
}
/**
* Lists the enabled features
*
* @return string[] a list of enabled features
*/
public static function getEnabled () {
$features = self::getAll();
$enabledFeatures = array_filter($features);
return array_keys($enabledFeatures);
}
-
}
diff --git a/tests/FeaturesTest.php b/tests/FeaturesTest.php
new file mode 100644
index 0000000..500f5af
--- /dev/null
+++ b/tests/FeaturesTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests;
+
+use Nasqueron\Notifications\Features;
+
+class FeaturesTest extends TestCase {
+ public function testEnable () {
+ // Find it (en vain …)
+ $this->assertNotContains('Quux', Features::getEnabled());
+ $this->assertFalse(Features::isEnabled('Quux'));
+
+ // Enable it
+ Features::enable('Quux');
+ $this->assertTrue(Features::isEnabled('Quux'));
+ $this->assertContains('Quux', Features::getEnabled());
+
+ // Disable it
+ Features::disable('Quux');
+ $this->assertFalse(Features::isEnabled('Quux'));
+
+ // Count it
+ $this->assertContains('Quux', Features::getAll());
+ $this->assertContains('Quux', Features::getAvailable());
+ $this->assertNotContains('Quux', Features::getEnabled());
+
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 14:49 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260425
Default Alt Text
(3 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment