Feature "checkers" are very similar to feature voters. Where feature voters are concerned with answering the question, feature checkers are more concerned with shuttling the question around to the service that can answer the question.
The bundle ships with two built-in feature checkers.
The VotingFeatureChecker implements a simple voting system.
It is the default feature checker in this bundle.
See Feature Voters for more information.
The InMemoryFeatureChecker is intended to be used in tests and doesn't support contextual information.
To create your own feature checker, implement j4nr6n/FeatureFlag/FeatureCheckerInterface.
// src/FeatureFlag/CustomFeatureChecker.php
use j4nr6n\FeatureFlagBundle\FeatureCheckerInterface;
class CustomFeatureChecker implements FeatureCheckerInterface
{
public function isEnabled(string $featureFlag, array $context = []): bool
{
// ...
}
}You'll then need to configure your application to pass this service when you ask for the feature checker service.
# config/packages/j4nr6n_feature_flag.yaml
j4nr6n_feature_flag:
feature_checker: 'App\FeatureFlag\CustomFeatureChecker'