diff --git a/README.md b/README.md index 42faea1ffc..16433065a4 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ In order to connect your application to Unleash you need to use a client SDK for - [Ruby SDK](https://docs.getunleash.io/sdks/ruby_sdk) - [Python SDK](https://docs.getunleash.io/sdks/python_sdk) - [.Net SDK](https://docs.getunleash.io/sdks/dot_net_sdk) +- [PHP SDK](https://docs.getunleash.io/sdks/php_sdk) **Official Frontend SDKs:** diff --git a/websitev2/docs/sdks/community.md b/websitev2/docs/sdks/community.md index a167458502..2795b88ee4 100644 --- a/websitev2/docs/sdks/community.md +++ b/websitev2/docs/sdks/community.md @@ -17,7 +17,6 @@ Community developed Client SDKs we already know about: - [afontaine/unleash_ex](https://gitlab.com/afontaine/unleash_ex) (Elixir) - [AppsFlyer/clojure-unleash](https://github.com/AppsFlyer/unleash-client-clojure) (Clojure) - [pmb0/nestjs-unleash](https://github.com/pmb0/nestjs-unleash) (NestJS - Node.js) -- [rikudou/unleash-sdk](https://github.com/RikudouSage/UnleashSDK) (PHP) - _...your implementation for your favorite language._ ### Implement your own SDK? {#implement-your-own-sdk} diff --git a/websitev2/docs/sdks/index.md b/websitev2/docs/sdks/index.md index 1f621174d2..ab7ebaf3ed 100644 --- a/websitev2/docs/sdks/index.md +++ b/websitev2/docs/sdks/index.md @@ -16,6 +16,7 @@ On this page you will find examples for connecting your application to the demo - [Ruby SDK](/sdks/ruby_sdk) - [Python SDK](/sdks/python_sdk) - [.Net SDK](/sdks/dot_net_sdk) +- [PHP SDK](/sdks/php_sdk) **Official Frontend Unleash Proxy SDKs:** diff --git a/websitev2/docs/sdks/php.md b/websitev2/docs/sdks/php.md new file mode 100644 index 0000000000..ab7fc94f52 --- /dev/null +++ b/websitev2/docs/sdks/php.md @@ -0,0 +1,79 @@ +--- +id: php_sdk +title: PHP SDK +--- + +In this guide we explain how to use feature toggles in a PHP application using Unleash-hosted. We will be using the open source Unleash [PHP Client SDK](https://github.com/Unleash/unleash-client-php). + +> You will need your `API URL` and your `API token` in order to connect the Client SDK to you Unleash instance. You can find this information in the “Admin” section Unleash management UI. [Read more](../user_guide/api-token) + +## Step 1: Install the client SDK {#step-1-install-the-client-sdk} + +First we must add Unleash Client SDK as a dependency to your project. Below is an example of how to install it via composer: + +```shell +composer require unleash/client guzzlehttp/guzzle symfony/cache +``` + +> Note: You can install any other PSR-16, PSR-17 and PSR-18 implementations instead of guzzlehttp/guzzle and symfony/cache + +## Step 2: Create a new Unleash Instance {#step-2-create-a-new-unleash-instance} + +Next we must initialize a new instance of the Unleash Client. + +```php +withAppName('my.php-app') + ->withInstanceId('your-instance-1') + ->withAppUrl('API URL') + ->withHeader('Authorization', 'API token') + ->build(); +``` + +In your app you typically just want one instance of Unleash, and inject that where you need it. You will typically use a dependency injection frameworks to manage this. + +You should change the URL and the Authorization header (API token) with the correct values for your instance, which you may locate under “Instance admin” in the menu. + +## Step 3: Use the feature toggle {#step-3-use-the-feature-toggle} + +Now that we have initialized the client SDK we can start using feature toggles defined in Unleash in our application. To achieve this we have the “isEnabled” method available, which will allow us to check the value of a feature toggle. This method will return **true** or **false** based on whether the feature should be enabled or disabled for the current request. + +```php +isEnabled("AwesomeFeature")) { + //do some magic +} else { + //do old boring stuff +} +``` + +Read more about the [Unleash architecture](https://www.unleash-hosted.com/articles/our-unique-architecture) to learn how it works in more details + +## Step 4: Provide Unleash Context {#step-4-provide-unleash-context} + +It is the client SDK that computes whether a feature toggle should be considered enabled or disabled for specific use request. This is the job of the [activation strategies](../user_guide/control_rollout), which are implemented in the client SDK. + +The activation strategies is an implementation of rules based on data, which you provide as part of the Unleash Context. + +**a) As argument to the isEnabled call** + +The simplest way to provide the Unleash Context is as part of the “isEnabled” call: + +```php +isEnabled("someToggle", $context); +``` + +> You can read more complete documentation in the [Client SDK repository](https://github.com/Unleash/unleash-client-php). diff --git a/websitev2/sidebars.js b/websitev2/sidebars.js index b4d6303161..3b550bb45d 100644 --- a/websitev2/sidebars.js +++ b/websitev2/sidebars.js @@ -34,6 +34,7 @@ module.exports = { 'sdks/go_sdk', 'sdks/python_sdk', 'sdks/ruby_sdk', + 'sdks/php_sdk', 'sdks/unleash-proxy', 'sdks/android_proxy_sdk', 'sdks/proxy-javascript',