Skip to content

Latest commit

 

History

History
81 lines (56 loc) · 1.43 KB

File metadata and controls

81 lines (56 loc) · 1.43 KB

Usage

Checking a flag

Feature::name() returns a FeatureState with isEnabled() and isDisabled():

use FeatureFlags\Feature;

if (Feature::name('NewCheckout')->isEnabled()) {
    // new flow
}

if (Feature::name('BetaDashboard')->isDisabled()) {
    throw new NotFoundException();
}

Nested flags use dot notation:

Feature::name('Reporting.AdvancedExport')->isEnabled();

Unknown flags resolve to disabled. No exception is thrown.

Common patterns

Controller:

if (Feature::name('NewCheckout')->isEnabled()) {
    $this->viewBuilder()->setTemplate('view_v2');
}

Template:

<?php
if (Feature::name('BetaDashboard')->isEnabled()):
    echo $this->element('dashboard/beta')
endif;
?>

Routes:

if (Feature::name('NewCheckout')->isEnabled()) {
    $routes->connect('/checkout', ['controller' => 'Checkout', 'action' => 'v2']);
}

Listing flags in code

use FeatureFlags\FeatureFlagsList;

$flags = FeatureFlagsList::asArray();
// raw Features array, nesting preserved

Console command

Print all configured flags as a table:

bin/cake feature_flags

Nested keys are flattened to dot notation; booleans render as true / false.

Testing

CakePHP's TestCase resets Configure between tests, so you can write flags directly:

Configure::write('Features.NewCheckout', true);
$this->assertTrue(Feature::name('NewCheckout')->isEnabled());