PHP code example of markstory / cakephp-feature-flags
1. Go to this page and download the library: Download markstory/cakephp-feature-flags library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
markstory / cakephp-feature-flags example snippets
use FeatureFlags\FeatureManagerInterface;
use FeatureFlags\Simple\FeatureManager;
public function services(ContainerInterface $container): void
{
$container->addShared(FeatureManagerInterface::class, function () {
return new FeatureManager(Configure::read('Features'));
});
}
public function view(FeatureManagerInterface $features, $id)
{
if ($features->has('calendar-v2')) {
// Logic for the new feature.
return $this->render();
}
...
}
return [
'Features' => [
// Each key is a feature name
'calendar-v2' => [
// Features are composed of many segments.
// All conditions in a segment must match for a feature to be
// granted
'segments' => [
// Segments can incrementally enable features
'rollout' => 50,
// Segments are composed of multiple conditions
'conditions' => [
[
'property' => 'user_email',
'op' => 'equal',
'value' => '[email protected]',
]
],
],
],
],
];
use FeatureFlags\FeatureManagerInterface;
use FeatureFlags\RuleBased\FeatureManager;
public function services(ContainerInterface $container): void
{
$container->addShared(FeatureManagerInterface::class, function () {
return new FeatureManager(
function (array $data) {
$context = [];
// Add properties to `$context` based on the data you use
// to check features.
return $context;
}
Configure::read('Features')
);
});
}
public function view(FeatureManagerInterface $features, $id)
{
// Including application data in `features->has` calls allows
// you to build custom feature logic that fits your application.
$identity = $this->request->getAttribute('identity');
if ($features->has('calendar-v2', ['user' => $identity])) {
// Logic for the new feature.
return $this->render();
}
...
}