You can now define feature flags in environment global variables or database.
You can use feature flag to easily switch off/on parts of TAO functionality.
IMPORTANT: It is recommended to use an external cache (i.e redis
) instead of phpfile
to avoid the need to restart the server after saving a feature flag.
php index.php 'oat\tao\scripts\tools\FeatureFlag\FeatureFlagTool' -s FEATURE_FLAG_EXAMPLE -v true
php index.php 'oat\tao\scripts\tools\FeatureFlag\FeatureFlagTool' -r true
php index.php 'oat\tao\scripts\tools\FeatureFlag\FeatureFlagTool' -i FEATURE_FLAG_EXAMPLE
Only available for DB feature flags
php index.php 'oat\tao\scripts\tools\FeatureFlag\FeatureFlagTool' -cc true
It is import tht we will use FEATURE_FLAG_
prefix for our feature flags to recognise them and their purpose.
To hide/show form fields you can extend AbstractFeatureFlagFormPropertyMapper
with your configurable service that has
OPTION_FEATURE_FLAG_FORM_FIELDS
mapped to list of fields that you want to hide/show.
<?php
use oat\taoLti\models\classes\LtiProvider\FeatureFlagFormPropertyMapper;
return new FeatureFlagFormPropertyMapper(
[
FeatureFlagFormPropertyMapper::OPTION_FEATURE_FLAG_FORM_FIELDS => [
'formField_01' => [
'FEATURE_FLAG_NAME'
]
]
]
);
This configuration will display formField_01
when FEATURE_FLAG_NAME
is enabled
tao/SectionVisibilityFilter
is responsible for listing sections that can be disabled from user. In order to add more
sections that have to be disabled/enabled based on feature flag.
<?php
return new oat\tao\model\menu\SectionVisibilityFilter(array(
'featureFlagSections' => [
'sectionName1' => [
'FEATURE_FLAG_01'
],
'sectionName2/actionName' => [
'FEATURE_FLAG_01'
]
],
'featureFlagSectionsToHide' => [
'sectionNameToHide1' => [
'FEATURE_FLAG_02'
],
'sectionNameToHide2/actionName' => [
'FEATURE_FLAG_02'
]
]
));
This configuration will display sectionName1
when FEATURE_FLAG_01
is enabled.
This configuration will display actionName
from sectionName2
when FEATURE_FLAG_01
is enabled.
This configuration will hide sectionNameToHide
when FEATURE_FLAG_02
is enabled.
This configuration will display actionName
from sectionNameToHide
when FEATURE_FLAG_02
is enabled.
These feature helps to dynamically overrride configs according to a featureFlag and therefore, no need for redeployment or server restart.
This is done though the FeatureFlagConfigSwitcher and composition with FeatureFlagConfigHandlerInterface by following the steps bellow:
- Create a handler implementing
FeatureFlagConfigHandlerInterface
.
Example:
declare(strict_types=1);
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\featureFlag\FeatureFlagConfigHandlerInterface;
class MyClientConfigHandler implements FeatureFlagConfigHandlerInterface
{
/** @var FeatureFlagCheckerInterface */
private $featureFlagChecker;
public function __invoke(array $configs): array
{
if ($this->featureFlagChecker->isEnabled('FEATURE_FLAG_EXAMPLE')) {
//change the config
}
//... apply another config changes if required
return $configs;
}
}
- Call the handler in your DI container definition.
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\model\featureFlag\FeatureFlagConfigSwitcher;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
class MyDIContainerServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$services->get(FeatureFlagConfigSwitcher::class)
->call(
'addClientConfigHandler',
[
MyClientConfigHandler::class,
]
)->call(
'addExtensionConfigHandler',
[
'taoQtiItem',
'qtiCreator',
MyExtensionConfigHandler::class
]
);
}
}
We currently support 2 types of configuration override on FeatureFlagConfigSwitcher
.
- The ones stored on
client_lib_config_registry.conf.php
, includingfeatureVisibility
. - The extension/module based ones.
use oat\tao\model\featureFlag\FeatureFlagConfigSwitcher;
/** @var FeatureFlagConfigSwitcher $featureFlagConfigSwitcher */
$featureFlagConfigSwitcher; // Get from DI container...
$configs = $featureFlagConfigSwitcher->getSwitchedExtensionConfig('taoQtiItem', 'qtiCreator'); // Config from extension
$configs = $featureFlagConfigSwitcher->getSwitchedClientConfig(); // Config from client_lib_config_registry.conf.php