['services' => ['label' => 'Services', 'enabled' => true, 'env' => 'SITE_SERVICES', 'hint' => 'The page with what you offer']] * * - the manager: a `resources` entry with `'feature' => 'services'` is left out when it is off (menu, permissions, screens, routes), * - the public site: `Features::on('services')`, the route middleware `manager.feature:services` (a 404 when off), the Blade * condition `@feature('services') … @endfeature`, and `Features::flags()` for what a page needs to know (links, sitemap). * * Off hides, it does not delete: the data stays where it is and comes back when the switch goes on again. The value lives at * `manager.features..enabled`, which is also the path the settings screen changes. */ final class Features { /** @return array */ public static function all(): array { $out = []; foreach ((array) config('manager.features', []) as $key => $definition) { if (! is_string($key) || preg_match('/^[a-z][a-z0-9_]{0,39}$/', $key) !== 1) { continue; } $definition = is_array($definition) ? $definition : ['enabled' => (bool) $definition]; $env = $definition['env'] ?? null; $out[$key] = [ 'key' => $key, 'label' => (string) ($definition['label'] ?? ucfirst(str_replace('_', ' ', $key))), 'hint' => isset($definition['hint']) ? (string) $definition['hint'] : null, 'enabled' => filter_var($definition['enabled'] ?? false, FILTER_VALIDATE_BOOLEAN), 'env' => is_string($env) && preg_match('/^[A-Z][A-Z0-9_]*$/', $env) === 1 ? $env : null, ]; } return $out; } /** Whether a feature is on. A name that is not a feature is off: nothing shows up that nobody declared. */ public static function on(string $key): bool { return (self::all()[$key]['enabled'] ?? false) === true; } /** @return array every feature and whether it is on, to hand to a page */ public static function flags(): array { return array_map(fn (array $feature) => $feature['enabled'], self::all()); } }