flagception / contentful-activator
Activator for manage feature toggles by contentful
Installs: 1 451
Dependents: 0
Suggesters: 1
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
Type:lib
Requires
- php: ^5.6||^7.0
- contentful/contentful: ^1.0||^2.0
- flagception/flagception: ^1.0
- symfony/options-resolver: >=2.7
Requires (Dev)
- phing/phing: ^2.15
- php-coveralls/php-coveralls: ^1.0
- phpunit/phpunit: ^5.5
- squizlabs/php_codesniffer: ^2.8
- symfony/phpunit-bridge: ^3.0
This package is auto-updated.
Last update: 2024-10-25 22:54:20 UTC
README
Manage feature flags for Flagception with Contentful!
Download the library
Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:
$ composer require flagception/contentful-activator
Usage
Just create a new ContentfulActivator
instance and commit it to your feature manager:
// YourClass.php class YourClass { public function run() { // We need two arguments: // 1. A contentful client // 2. The content type name in contentful $activator = new ContentfulActivator($this->client, 'FeatureToggle'); $manager = new FeatureManager($activator); if ($manager->isActive('your_feature_name')) { // do something } } }
The ContentfulActivator
need three arguments:
- An instance of a contentful client
- The contentful model type id as string
- The field mappings as array ('name' and 'state') - Optional (default values are set)
If your contentful model looks like this ...
{ "name": "Feature Management", "description": "Features verwalten", "displayField": "featureName", "fields": [ { "id": "featureName", "name": "Feature", "type": "Text", "localized": false, "required": true, "validations": [], "disabled": false, "omitted": false }, { "id": "isActive", "name": "Aktiv", "type": "Boolean", "localized": false, "required": true, "validations": [], "disabled": false, "omitted": false } ], "sys": { "space": { "sys": { "type": "Link", "linkType": "Space", "id": "9d8smn39" } }, "id": "myFeatureModel", "type": "ContentType", "createdAt": "2017-12-07T15:54:07.255Z", "updatedAt": "2018-01-11T16:08:47.283Z", //... } }
... then your activator instance should be like this:
// YourClass.php class YourClass { public function run() { // "myFeatureModel" is the content model type $activator = new ContentfulActivator($this->client, 'myFeatureModel', [ 'name' => 'featureName', // Field name for feature key 'state' => 'isActive' // Field name for feature state ]); $manager = new FeatureManager($activator); if ($manager->isActive('your_feature_name')) { // do something } } }
You can skip the field mapping (like the first example) if you use the default field names in contentful:
- 'state' for the feature state field
- 'name' for the feature key field