optimizely / optimizely-sdk
Optimizely PHP SDK for Optimizely Feature Experimentation, Optimizely Full Stack (legacy), and Optimizely Rollouts
Installs: 1 158 595
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 101
Forks: 29
Open Issues: 2
Requires
- php: >=8.1
- guzzlehttp/guzzle: >=6.2
- justinrainbow/json-schema: ^1.6 || ^2.0 || ^4.0 || ^5.0
- lastguest/murmurhash: ^1.3.0
- monolog/monolog: >=1.21
Requires (Dev)
- icecave/parity: ^3.0.1
- php-coveralls/php-coveralls: v2.5.3
- phpunit/phpunit: ^9.3
- squizlabs/php_codesniffer: 3.7
- dev-master
- 4.0.1
- 4.0.0
- 3.x-dev
- 3.10.0
- 3.9.4
- 3.9.3.x-dev
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.0
- 3.7.1
- 3.7.0
- 3.6.x-dev
- 3.6.1
- 3.6.0
- 3.5.x-dev
- 3.5.0
- 3.4.x-dev
- 3.4.0
- 3.3.x-dev
- 3.3.1
- 3.3.0
- 3.2.x-dev
- 3.2.0
- 3.1.x-dev
- 3.1.0
- 3.0.1
- 3.0.0
- 2.2.x-dev
- 2.2.1
- 2.2.0
- 2.1.x-dev
- 2.1.0
- 2.0.x-dev
- 2.0.1
- 2.0.0
- 2.0.0-beta1
- 1.5.x-dev
- 1.5.0
- 1.4.0
- 1.3.x-dev
- 1.3.0
- 1.2.x-dev
- 1.2.0
- 1.1.x-dev
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- 0.1.0
- dev-mke
- dev-sohail/prep_3.9.2
- dev-uzair/changelogs
- dev-pr-253
- dev-uzair/test-with-fsc
- dev-mnoman/gitAction
- dev-pr-243
- dev-pr-242
- dev-sohail/test
- dev-uzair/experiment-map-deprecation
- dev-yasir/config-v2
- dev-zeeshan/decide-api
- dev-pr/211
This package is not auto-updated.
Last update: 2024-11-05 02:18:08 UTC
README
This repository houses the PHP SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy).
Optimizely Feature Experimentation is an A/B testing and feature management tool for product development teams that enables you to experiment at every step. Using Optimizely Feature Experimentation allows for every feature on your roadmap to be an opportunity to discover hidden insights. Learn more at Optimizely.com, or see the developer documentation.
Optimizely Rollouts is free feature flags for development teams. You can easily roll out and roll back features in any application without code deploys, mitigating risk for every feature on your roadmap.
Get Started
Refer to the PHP SDK's developer documentation for detailed instructions on getting started with using the SDK.
Requirements
To access the Feature Management configuration in the Optimizely dashboard, please contact your Optimizely account executive.
SDK version 4.0.0 requires PHP8+. SDK version 3 requires PHP5.5+ up to PHP7.
Install the SDK
The Optimizely PHP SDK can be installed through Composer. Please use the following command:
php composer.phar require optimizely/optimizely-sdk
Use the PHP SDK
Initialization
Create the Optimizely client, for example:
<?php use Optimizely\Optimizely; $optimizely = new Optimizely(<<DATAFILE>>);
Or you may also use OptimizelyFactory method to create an optimizely client using your SDK key, an optional fallback datafile and an optional datafile access token. Using this method internally creates an HTTPProjectConfigManager. See HTTPProjectConfigManager for further detail.
<?php use Optimizely\OptimizelyFactory; $optimizelyClient = OptimizelyFactory::createDefaultInstance( "your-sdk-key", <<DATAFILE>>, <<DATAFILE_AUTH_TOKEN>> );
To access your HTTPProjectConfigManager:
<?php use Optimizely\Optimizely; /** @var Optimizely $optimizelyClient */ $configManager = $optimizelyClient->configManager;
Or you can also provide an implementation of the ProjectConfigManagerInterface
in the constructor:
<?php use Optimizely\Optimizely; use Optimizely\ProjectConfigManager\HTTPProjectConfigManager; $configManager = new HTTPProjectConfigManager(<<SDK_KEY>>); $optimizely = new Optimizely( <<DATAFILE>>, null, null, null, false, null, $configManager );
ProjectConfigManagerInterface
ProjectConfigManagerInterface
exposes getConfig
method for retrieving ProjectConfig
instance.
HTTPProjectConfigManager
HTTPProjectConfigManager
is an implementation of ProjectConfigManagerInterface
interface.
The fetch
method makes a blocking HTTP GET request to the configured URL to download the
project datafile and initialize an instance of the ProjectConfig.
Calling fetch
will update the internal ProjectConfig instance that will be returned by getConfig
.
Use HTTPProjectConfigManager
<?php use Optimizely\ProjectConfigManager\HTTPProjectConfigManager; $configManager = new HTTPProjectConfigManager(<<SDK_KEY>>);
SDK key
Optimizely project SDK key; required unless source URL is overridden.
A notification will be triggered whenever a new datafile is fetched and ProjectConfig is updated. To subscribe to these notifications, use the $notificationCenter->addNotificationListener(NotificationType::OPTIMIZELY_CONFIG_UPDATE, $updateCallback)
.
SDK Development
Unit Tests
You can run all unit tests with:
./vendor/bin/phpunit
Contributing
Please see CONTRIBUTING.
Other Optimizely SDKs
-
Flutter - https://github.com/optimizely/optimizely-flutter-sdk
-
JavaScript - https://github.com/optimizely/javascript-sdk