PHP code example of rasuvaeff / yii3-feature-flags
1. Go to this page and download the library: Download rasuvaeff/yii3-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/ */
rasuvaeff / yii3-feature-flags example snippets
use Rasuvaeff\Yii3FeatureFlags\FeatureFlags;
use Rasuvaeff\Yii3FeatureFlags\FlagContext;
if ($featureFlags->isEnabled(
flag: 'new-checkout',
context: FlagContext::forUser(userId: $userId),
)) {
// New checkout flow.
}
use Rasuvaeff\Yii3FeatureFlags\Flag;
use Rasuvaeff\Yii3FeatureFlags\WritableFlagProvider;
/** @var WritableFlagProvider $provider */
$provider->save(flag: new Flag(name: 'new-checkout', rollout: 25));
$provider->remove(name: 'old-checkout');
use Rasuvaeff\Yii3FeatureFlags\FeatureFlags;
use Rasuvaeff\Yii3FeatureFlags\MetricsRecorder;
$recorder = new class implements MetricsRecorder {
#[\Override]
public function recordEvaluation(\Rasuvaeff\Yii3FeatureFlags\EvaluationResult $result): void
{
// ship $result->getReason()->value to your metrics backend
}
};
$featureFlags = new FeatureFlags(provider: $provider, recorder: $recorder);