{"id":18576133,"url":"https://github.com/thiagodp/phputil-flags","last_synced_at":"2026-02-10T04:31:26.515Z","repository":{"id":239218229,"uuid":"797547805","full_name":"thiagodp/phputil-flags","owner":"thiagodp","description":"A lightweight, extensible feature flags framework for PHP","archived":false,"fork":false,"pushed_at":"2024-11-09T21:33:03.000Z","size":66,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-19T01:46:30.738Z","etag":null,"topics":["feature","flag","framework","library","php","toggle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thiagodp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-08T03:53:04.000Z","updated_at":"2024-11-09T21:33:04.000Z","dependencies_parsed_at":"2025-04-10T08:36:52.043Z","dependency_job_id":"0905441d-7f2c-4c9d-bbd3-a2844ff9244b","html_url":"https://github.com/thiagodp/phputil-flags","commit_stats":null,"previous_names":["thiagodp/phputil-flags"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/thiagodp/phputil-flags","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fphputil-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fphputil-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fphputil-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fphputil-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiagodp","download_url":"https://codeload.github.com/thiagodp/phputil-flags/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fphputil-flags/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29290990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T03:42:42.660Z","status":"ssl_error","status_checked_at":"2026-02-10T03:42:41.897Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feature","flag","framework","library","php","toggle"],"created_at":"2024-11-06T23:23:43.604Z","updated_at":"2026-02-10T04:31:26.453Z","avatar_url":"https://github.com/thiagodp.png","language":"PHP","readme":"# phputil/flags\n\n[![Version](https://poser.pugx.org/phputil/flags/v?style=flat-square)](https://packagist.org/packages/phputil/flags)\n![Build](https://github.com/thiagodp/phputil-flags/actions/workflows/ci.yml/badge.svg?style=flat)\n[![License](https://poser.pugx.org/phputil/flags/license?style=flat-square)](https://packagist.org/packages/phputil/flags)\n[![PHP](http://poser.pugx.org/phputil/flags/require/php)](https://packagist.org/packages/phputil/flags)\n\n\n\u003e 🚩 A lightweight, customizable [feature flags](https://en.wikipedia.org/wiki/Feature_toggle) framework for PHP\n\nYou can customize:\n- 🧠 How flags are evaluated, through [Strategies](#strategies).\n- 💾 How flags are stored, through [Storages](#storages).\n- 📢 Who is notified about flag changes or removal, through [Listeners](#listeners).\n\n\n## Installation\n\n\u003e PHP 7.4 or later. No external dependencies.\n\n```bash\ncomposer require phputil/flags\n```\n👉 You may also like to install some of the official [extensions](#extensions).\n\n\n## Extensions\n\nOfficial extensions:\n\n- [`phputil/flags-pdo`](https://github.com/thiagodp/phputil-flags-pdo) - a [PDO](https://www.php.net/manual/en/intro.pdo.php)-based [storage](#storages).\n- ⏳ SOON - [`phputil/flags-firebase`](https://github.com/thiagodp/phputil-flags-firebase) - a [Firebase](https://firebase.google.com/)-based [storage](#storages).\n- [`phputil/flags-webhooks`](https://github.com/thiagodp/phputil-flags-webhooks) a [listener](#listeners) that works like a webhook, by notifying external APIs about flags' changes.\n\nThird-party extensions:\n- Create yours and open an Issue to be evaluated. It may appear here.\n\n\n## Usage\n\nBasic flag checking:\n\n```php\nrequire_once 'vendor/autoload.php';\nuse phputil\\flags\\FlagManager;\n\n// By default, it uses a storage-based strategy with an in-memory storage\n$flag = new FlagManager();\n\nif ( $flag-\u003eisEnabled( 'my-cool-feature' ) ) {\n    echo 'Cool feature available!', PHP_EOL;\n} else {\n    echo 'Not-so-cool feature here', PHP_EOL;\n}\n```\n\nCustomizing a certain verification:\n```php\n// ...\nuse phputil\\flags\\FlagVerificationStrategy;\n\n$flag = new FlagManager();\n\n$myLuckBasedStrategy = new class implements FlagVerificationStrategy {\n    function isEnabled( string $flag ): bool {\n        return rand( 1, 100 ) \u003e= 50; // 50% chance\n    }\n};\n\nif ( $flag-\u003eisEnabled( 'my-cool-feature', [ $myLuckBasedStrategy ] ) ) {\n    echo 'Cool feature available!', PHP_EOL;\n} else {\n    echo 'Not-so-cool feature here', PHP_EOL;\n}\n```\n\nCustomizing all the verifications:\n\n```php\n$flag = new FlagManager( null, [ $myLuckBasedStrategy ] );\n\nif ( $flag-\u003eisEnabled( 'my-cool-feature' ) ) {\n    ...\n```\n\nSetting a flag:\n```php\n$flag-\u003eenable( 'my-cool-feature' );\n$flag-\u003edisable( 'my-cool-feature' );\n$flag-\u003esetEnable( 'my-cool-feature', true /* or false */ );\n```\n\nRemoving a flag:\n```php\n$flag-\u003eremove( 'my-cool-feature' );\n```\n\nRetrieving flag data:\n```php\n$flagData = $flag-\u003egetStorage()-\u003eget( 'my-cool-feature' ); // null if not found\n```\n\nAdding a listener:\n```php\n// ...\nuse phputil\\flags\\FlagListener;\nuse phputil\\flags\\FlagData;\n\n$myListener = new class implements FlagListener {\n  public function notify( string $event, FlagData $flagData ): void {\n    if ( $event === 'change' ) {\n        echo 'Flag ', $flagData-\u003ekey, ' is now ', $flagData-\u003eenabled ? 'enabled': 'disabled', PHP_EOL;\n    } else if ( $event === 'removal' ) {\n        echo 'Flag ', $flagData-\u003ekey, ' was removed.', PHP_EOL;\n    }\n  }\n};\n\n$flag-\u003eaddListener( $myListener ); // v0.5.0+\n// or $flag-\u003egetListeners()-\u003eadd( $myListener );\n\n$flag-\u003eenable( 'my-cool-feature' ); // Notify the listener\n```\n\n## Customization\n\n\n### Storages\n\nUse a different flag storage by:\n- Creating your own, extending [`FlagStorage`](/src/FlagStorage.php); OR\n- Using an external [storage extension](#extensions).\n\nHow to configure it:\n\n```php\n$storage = /* Create your storage here, e.g. new InMemoryStorage() */;\n$flag = new FlagManager( $storage );\n```\n\nStorages available in the framework:\n- [`InMemoryStorage`](src/storages/InMemoryStorage.php), that store flags in memory.\n\n### Strategies\n\nUse a flag verification strategy by:\n- Creating your own, extending [`FlagVerificationStrategy`](/src/FlagVerificationStrategy.php); OR\n- Using an external [strategy extension](#extensions).\n\nHow to configure it globally:\n\n```php\n$strategies = [ /* pass your strategies here   */ ];\n$flag = new FlagManager( null, $strategies );\n```\n\nStrategies available in the framework:\n- [`StorageBasedVerificationStrategy`](src/strategies/StorageBasedVerificationStrategy.php), that checks flags in a storage.\n- [`EnvBasedVerificationStrategy`](src/strategies/EnvBasedVerificationStrategy.php), that checks flags based on environment variables.\n\n👉 A flag is considered enabled when **all** the strategies considered it enabled.\n\n\n### Listeners\n\nDefine a listener by:\n- Creating your own, extending [`FlagListener`](/src/FlagListener.php); OR\n- Using an external [listener extension](#extensions).\n\nHow to configure it:\n\n```php\n$flag-\u003eaddListener( $myListener ); // v0.5.0+\n// or $flag-\u003egetListeners()-\u003eadd( $myListener );\n```\n\n\n## Roadmap\n\n- [x] Extensible library\n- [ ] Official extensions:\n  - [x] PDO-based storage\n  - [ ] Firebase-based storage\n  - [x] Webhook-like listener\n- [ ] REST API (external repository)\n- [ ] Web-based control panel (external repository)\n\n\n## License\n\n[MIT](/LICENSE) © [Thiago Delgado Pinto](https://github.com/thiagodp)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fphputil-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagodp%2Fphputil-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fphputil-flags/lists"}