Contentful activator for flagception
Manage feature flags for Flagception with Contentful!, (*1)
, (*2)
, (*3)
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:, (*4)
$ composer require flagception/contentful-activator
Usage
Just create a new ContentfulActivator
instance and commit it to your feature manager:, (*5)
// 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), (*6)
If your contentful model looks like this ..., (*7)
{
"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:, (*8)
// 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, (*9)