Download the PHP package featurit/featurit-sdk-symfony without Composer
On this page you can find all versions of the php package featurit/featurit-sdk-symfony. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download featurit/featurit-sdk-symfony
More information about featurit/featurit-sdk-symfony
Files in featurit/featurit-sdk-symfony
Informations about the package featurit-sdk-symfony
FeaturIT SDK for Symfony
Symfony wrapper of the PHP client for the FeaturIT Feature Flag management platform.
Description
This package aims to simplify the integration of the FeaturIT API in a Symfony project.
Getting started
Dependencies
- PHP >= 8.0.2
- symfony/framework-bundle >= 5.2
- psr/http-client-implementation
- psr/simple-cache-implementation
Installing
composer require featurit/featurit-sdk-symfony -W
If there's no package providing psr/http-client-implementation, visit https://packagist.org/providers/psr/http-client-implementation and choose the package that better suits your project.
If there's no package providing psr/simple-cache-implementation, visit https://packagist.org/providers/psr/simple-cache-implementation and choose the package that better suits your project.
Inside your config/bundles.php file, add:
If you want to create your own configuration file in order to customize things
like the default FeaturitUserContextProvider, create a file in config/packages/featurit.yaml
with the following contents:
You also need to create the proper environment variables in your .env
file.
Basic Usage
That's how you would use Featurit in one of your controllers, services, or anywhere inside your PHP codebase:
Or in order to check which is the version of your feature:
Twig extension
For convenience we provide 2 twig functions which allow to render html depending on the Feature Flag values.
Inside your twig template, you can use them like this:
Defining your FeaturitUserContext
In order to show different versions of a feature to different users, Featurit needs to know about the attributes your user has in a certain context.
You can define the context using the as follows:
Defining a custom FeaturitUserContextProvider
This is an alternative to using $featurit->setUserContext(...);
.
By default, Featurit SDK for Symfony comes with a default FeaturitUserContextProvider
adapted for Symfony, but if you want to create your own, create a service un your services.yaml
file as follows:
And then add it to the featurit.yaml
config file as:
Let's say that your platform users have a "role" attribute that you use to decide which features you show to each user. In that case you could create an implementation like:
Then you must replace your implementation in the featurit.yaml
file as explained before.
And that should do it, from now on your segmentation rules will use the role attribute.
Event Tracking
In order to track some event in your application, you can add this once the event has happened:
All the events you track in the same request will be accumulated and associated to the current FeaturitUserContext, if for some reason you want to send the event immediately, you can do as follows:
Custom cache implementation
By default, FeaturIT SDK for Symfony provides a simple File cache.
Once you have multiple servers, you will want to inject your custom Psr\SimpleCache\CacheInterface
implementation
using some distributed cache system.
This can be done as follows:
Authors
FeaturIT
All versions of featurit-sdk-symfony with dependencies
featurit/featurit-sdk-php Version ^1.0.0
symfony/framework-bundle Version ^5.2 || ^6.0 || ^7.0
nyholm/psr7 Version ^1.5