eleme / feature
Feature API used for operational Dark Launching ad A/B Testing.
Installs: 2 806
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.3
Requires (Dev)
- satooshi/php-coveralls: dev-master
- silex/silex: ~1.1
- twig/twig: 1.*
This package is not auto-updated.
Last update: 2024-11-09 14:14:27 UTC
README
Feature API used for operational Dark Launching ad A/B Testing.
Install With Composer:
"require": { "eleme/feature": "~0.1" }
Features Example:
<?php use Feature\Features; require_once(__DIR__.'/../vendor/autoload.php'); $user = array( 'name' => 'a', 'admin' => false, ); $config = array( 'featureA' => true, 'featureB' => function () use ($user) { return $user['admin']; }, 'featureC' => function () use ($user) { return $user['name'] == 'a' ? 'foo' : 'bar'; }, 'featureD' => 'd', ); $features = new Features($config); echo var_export($features->variant('featureA')), "\n"; // true echo var_export($features->variant('featureB')), "\n"; // false echo var_export($features->variant('featureC')), "\n"; // 'foo' echo var_export($features->variant('featureD')), "\n"; // 'd' echo var_export($features->variant('featureZ')), "\n"; // false
Service Provider With Silex:
<?php use Silex\Application; use Feature\Provider\Silex\FeaturesServiceProvider; require_once(__DIR__.'/../vendor/autoload.php'); $app = new Application(); $app->register(new FeaturesServiceProvider); $app['features.config'] = array( 'featureA' => true, ); echo var_export($app['features']->variant('featureA')), "\n"; // true
Twig Extension:
in php:
<?php use Feature\Features; use Feature\Provider\Twig\Feature; require_once(__DIR__.'/../vendor/autoload.php'); $options = getopt('u:'); $user = isset($options['u']) && $options['u'] === 'admin' ? 'admin' : 'user'; $config = array( 'foo' => true, 'bar' => function () use ($user) { return $user === 'admin' ? 'admin' : 'user'; }, ); $features = new Features($config); $loader = new Twig_Loader_Filesystem(__DIR__.'/templates'); $twig = new Twig_Environment($loader); $twig->addExtension(new Feature($features)); echo $twig->render('foo.twig');
in twig:
{% feature foo %} foo ok {% endfeature %} {% feature bar - admin %} bar admin {% endfeature %} {% feature bar - user %} bar user {% endfeature %}