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.
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']);
}use FeatureFlags\FeatureFlagsList;
$flags = FeatureFlagsList::asArray();
// raw Features array, nesting preservedPrint all configured flags as a table:
bin/cake feature_flags
Nested keys are flattened to dot notation; booleans render as true / false.
CakePHP's TestCase resets Configure between tests, so you can write flags directly:
Configure::write('Features.NewCheckout', true);
$this->assertTrue(Feature::name('NewCheckout')->isEnabled());