Skip to content

Commit 5e4606c

Browse files
committed
Add documentation
1 parent 9db270c commit 5e4606c

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
LaunchDarkly SDK for PHP
2+
===========================
3+
4+
Quick setup
5+
-----------
6+
7+
0. Install the PHP SDK with [Composer](https://getcomposer.org/)
8+
9+
php composer.phar require launchdarkly/launchdarkly-php
10+
11+
1. After installing, require Composer's autoloader:
12+
13+
require 'vendor/autoload.php';
14+
15+
2. Create a new LDClient with your API key:
16+
17+
$client = new LaunchDarkly\LDClient("your_api_key");
18+
19+
Your first feature flag
20+
-----------------------
21+
22+
1. Create a new feature flag on your [dashboard](https://app.launchdarkly.com)
23+
24+
2. In your application code, use the feature's key to check whether the flag is on for each user:
25+
26+
$user = new LaunchDarkly\LDUser("[email protected]");
27+
if ($client->getFlag("your.flag.key", $user)) {
28+
# application code to show the feature
29+
} else {
30+
# the code to run if the feature is off
31+
}

src/LaunchDarkly/FeatureRep.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace LaunchDarkly;
33

4+
/**
5+
* @internal
6+
*/
47
class FeatureRep {
58
protected static $LONG_SCALE = 0xFFFFFFFFFFFFFFF;
69

src/LaunchDarkly/LDClient.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
use \GuzzleHttp\Exception\BadResponseException;
55
use \GuzzleHttp\Subscriber\Cache\CacheSubscriber;
66

7+
/**
8+
* A client for the LaunchDarkly API.
9+
*/
710
class LDClient {
811
const DEFAULT_BASE_URI = 'https://app.launchdarkly.com';
912
const VERSION = '0.1.0';
@@ -12,6 +15,16 @@ class LDClient {
1215
protected $_baseUri;
1316
protected $_client;
1417

18+
/**
19+
* Creates a new client instance that connects to LaunchDarkly.
20+
*
21+
* @param string $apiKey The API key for your account
22+
* @param array $options Client configuration settings
23+
* - base_uri: Base URI of the LaunchDarkly API. Defaults to `DEFAULT_BASE_URI`
24+
* - timeout: Float describing the maximum length of a request in seconds. Defaults to 3
25+
* - connect_timeout: Float describing the number of seconds to wait while trying to connect to a server. Defaults to 3
26+
* - cache_storage: An optional GuzzleHttp\Subscriber\Cache\CacheStorageInterface. Defaults to an in-memory cache.
27+
*/
1528
public function __construct($apiKey, $options = []) {
1629
$this->_apiKey = $apiKey;
1730
$this->_baseUri = $options['base_uri'] ? rtrim($options['base_uri'], '/') : self::DEFAULT_BASE_URI;
@@ -25,6 +38,15 @@ public function __construct($apiKey, $options = []) {
2538
$this->_client = $this->_make_client($options);
2639
}
2740

41+
/**
42+
* Calculates the value of a feature flag for a given user.
43+
*
44+
* @param string $key The unique key for the feature flag
45+
* @param LDUser $user The end user requesting the flag
46+
* @param boolean $default The default value of the flag
47+
*
48+
* @return boolean Whether or not the flag should be enabled, or `default` if the flag is disabled in the LaunchDarkly control panel
49+
*/
2850
public function getFlag($key, $user, $default = false) {
2951
try {
3052
$flag = $this->_getFlag($key, $user, $default);

src/LaunchDarkly/LDUser.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
<?php
22
namespace LaunchDarkly;
33

4+
/**
5+
* Contains specific attributes of a user browsing your site. The only mandatory property property is the key,
6+
* which must uniquely identify each user. For authenticated users, this may be a username or e-mail address. For anonymous users,
7+
* this could be an IP address or session ID.
8+
*/
49
class LDUser {
510
protected $_key = null;
611
protected $_secondary = null;
712
protected $_ip = null;
813
protected $_country = null;
914
protected $_custom = [];
1015

16+
/**
17+
* @param string $key Unique key for the user. For authenticated users, this may be a username or e-mail address. For anonymous users, this could be an IP address or session ID.
18+
* @param string|null $secondary An optional secondary identifier
19+
* @param string|null $ip The user's IP address (optional)
20+
* @param string|null $country The user's country, as an ISO 3166-1 alpha-2 code (e.g. 'US') (optional)
21+
* @param array $custom Other custom attributes that can be used to create custom rules
22+
*/
1123
public function __construct($key, $secondary = null, $ip = null, $country = null, $custom = []) {
1224
$this->_key = $key;
1325
$this->_secondary = $secondary;
@@ -16,7 +28,6 @@ public function __construct($key, $secondary = null, $ip = null, $country = null
1628
$this->_custom = $custom;
1729
}
1830

19-
2031
public function getCountryCode() {
2132
return $this->_country;
2233
}

src/LaunchDarkly/TargetRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace LaunchDarkly;
33

4+
/**
5+
* @internal
6+
*/
47
class TargetRule {
58
protected $_attribute = null;
69
protected $_operator = null;

src/LaunchDarkly/Variation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace LaunchDarkly;
33

4+
/**
5+
* @internal
6+
*/
47
class Variation {
58
protected $_value = null;
69
protected $_weight = 0;

0 commit comments

Comments
 (0)