2017 © Pedro Peláez
 

lib contentful-activator

Activator for manage feature toggles by contentful

image

flagception/contentful-activator

Activator for manage feature toggles by contentful

  • Sunday, January 14, 2018
  • by bestit
  • Repository
  • 4 Watchers
  • 1 Stars
  • 523 Installations
  • PHP
  • 2 Dependents
  • 3 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 97 % Grown

The README.md

Contentful activator for flagception

Manage feature flags for Flagception with Contentful!, (*1)

Latest Stable Version Coverage Status Build Status Total Downloads License, (*2)

SensioLabsInsight, (*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)

The Versions

14/01 2018

dev-master

9999999-dev

Activator for manage feature toggles by contentful

  Sources   Download

MIT

The Requires

 

The Development Requires

contentful flagception contentful-extension activator

14/01 2018

1.0.0

1.0.0.0

Activator for manage feature toggles by contentful

  Sources   Download

MIT

The Requires

 

The Development Requires

contentful flagception contentful-extension activator