graymatterlabs / experiment
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.9
- graymatterlabs/simple-cache: ^1.1
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- psr/simple-cache: ^3.0
Suggests
- graymatterlabs/simple-cache: ^1.1
- psr/simple-cache: ^3.0
This package is auto-updated.
Last update: 2024-10-09 22:34:47 UTC
README
This package makes no opinions on how you store your experiment data. Bring your own implementation of GrayMatterLabs\Experiment\Contracts\Persistence
or use one of the provided implementations.
How you choose to implement your GrayMatterLabs\Experiment\Contracts\Factory
will determine how you reference your experiments throughout the code. By default, there is an implementation provided that references experiments by their fully qualified class names.
Similarly, you may choose to and are encouraged to configure your experiments in a dynamic and/or data-backed way by instantiating them with data from any number of storage mechanisms as well as in any shape you see fit.
In general, this package attempts to not strictly enforce opinions as much as possible but rather provide an open-ended framework for A/B testing that minimizes complexity and overhead. You are encouraged to bring your own concrete implementations of the provided interfaces. You can, however, lean into the implementations provided for you.
Installation
You can install the package via composer:
composer require graymatterlabs/experiment:^0.3
Usage
$manager = new Manager($persistence, $factory, $strategy); $sample = new Sample(); $allocation = $manager->allocate($experiment, $sample); if (! $allocation->isAllocated()) { // unable to allocate } if ($allocation->isVariant('TEST')) { // execute experimental feature } if ($allocation->wasRecentlyAllocated) { // the allocation is new }
Note: Usage of
GrayMatterLabs\Experiment\Persistence\SimpleCachePersistence
requires you satisfy thePsr\SimpleCache\CacheInterface
interface. See graymatterlabs/simple-cache or bring your own implementation.
Testing
composer test
Changelog
Please see the Release Notes for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.