- How do I install antfroger/progressive in a Laravel project?
- Run `composer require antfroger/progressive` to install the package. If using Laravel, publish the config with `php artisan vendor:publish --tag=progressive-config` to customize settings via `.env` or `config/progressive.php`. No additional setup is required for basic usage.
- Can I use progressive feature flags in vanilla PHP (non-Laravel) projects?
- Yes, the package is designed to work outside Laravel. Initialize it with a config array or YAML file, then use `new Progressive($config)` to check flags. Laravel-specific features like service providers or Facades won’t be available, but core functionality remains intact.
- What Laravel versions does antfroger/progressive support?
- The package is compatible with Laravel 9+ and PHP 8.1+. Older Laravel versions may require minor adjustments due to PHP 8.1’s named arguments, but no breaking changes exist for newer PHP versions. Test thoroughly if using Laravel 8 or below.
- How do I store feature flags persistently (e.g., in a database) for dynamic updates?
- Use Eloquent models to store flags in a database. Create a `flags` table with columns like `name`, `enabled`, and `conditions` (as JSON). Seed initial flags via a migration or seeder, then fetch them dynamically in your `Progressive` config. This avoids redeploys for flag changes.
- Does antfroger/progressive support custom rules for user segments or time-based flags?
- Yes, you can add custom rules using `addCustomRule()`. For example, restrict a flag to specific environments with `$progressive->addCustomRule('env', fn(Context $context, array $envs) => in_array(getenv('ENV'), $envs))`. This allows complex logic like user roles, IP ranges, or time-based conditions.
- What happens if the flag service fails in production? Can I set a fallback?
- By default, the package throws an exception if the service fails. To implement a fallback (e.g., default to `false`), wrap flag checks in a try-catch block or extend the `Progressive` class to override error handling. This is useful for graceful degradation.
- How do I test feature flags in PHPUnit? Can I mock flag states?
- Mock flags by directly setting the config array or using dependency injection. For example, in a test: `$progressive = new Progressive(['features' => ['test-flag' => true]]);` or mock the `isEnabled()` method in your service layer. Test edge cases like malformed conditions or disabled flags.
- Is there built-in caching for feature flags? How can I optimize performance?
- The package has no built-in caching, but you can integrate Redis/Memcached by extending the `Progressive` class or wrapping flag checks in a cache layer (e.g., `Cache::remember`). For high-traffic apps, cache flag evaluations for 5–10 minutes to reduce database or config file reads.
- Can I use antfroger/progressive for A/B testing or percentage-based rollouts?
- Yes, create a custom rule to randomize flag evaluation. For example, enable a flag for 10% of users with `$progressive->addCustomRule('percent', fn(Context $context, int $percent) => rand(1, 100) <= $percent)`. Combine this with user IDs for consistent targeting across sessions.
- What are the alternatives to antfroger/progressive for Laravel feature flags?
- Alternatives include `spatie/laravel-feature-flags` (Laravel-specific, more features), `flagsmith/flagsmith-php` (SaaS-backed), or `launchdarkly/php-sdk` (enterprise-grade). `antfroger/progressive` stands out for its simplicity, no Laravel constraints, and lightweight design—ideal for projects needing minimal dependencies.