LDClient
in package
A client for the LaunchDarkly API.
Table of Contents
- DEFAULT_BASE_URI = 'https://sdk.launchdarkly.com'
- DEFAULT_EVENTS_URI = 'https://events.launchdarkly.com'
- VERSION = '4.2.2'
- The current SDK version.
- __construct() : LDClient
- Creates a new client instance that connects to LaunchDarkly.
- alias() : void
- Associates two users for analytics purposes.
- allFlagsState() : FeatureFlagsState
- Returns an object that encapsulates the state of all feature flags for a given user.
- flush() : bool
- Publishes any pending analytics events to LaunchDarkly.
- identify() : void
- Reports details about a user.
- isOffline() : bool
- Returns whether the LaunchDarkly client is in offline mode.
- secureModeHash() : string
- Generates an HMAC sha256 hash for use in Secure mode.
- track() : void
- Tracks that a user performed an event.
- variation() : mixed
- Calculates the value of a feature flag for a given user.
- variationDetail() : EvaluationDetail
- Calculates the value of a feature flag, and returns an object that describes the way the value was determined.
Constants
DEFAULT_BASE_URI
public
string
DEFAULT_BASE_URI
= 'https://sdk.launchdarkly.com'
DEFAULT_EVENTS_URI
public
string
DEFAULT_EVENTS_URI
= 'https://events.launchdarkly.com'
VERSION
The current SDK version.
public
string
VERSION
= '4.2.2'
Methods
__construct()
Creates a new client instance that connects to LaunchDarkly.
public
__construct(string $sdkKey[, array<string|int, mixed> $options = [] ]) : LDClient
Parameters
- $sdkKey : string
-
The SDK key for your account
- $options : array<string|int, mixed> = []
-
Client configuration settings
-
base_uri
: Base URI of the LaunchDarkly service. Change this if you are connecting to a Relay Proxy instance instead of directly to LaunchDarkly. To learn more, read The Relay Proxy. -
events_uri
: Base URI for sending events to LaunchDarkly. Change this if you are forwarding events through a Relay Proxy instance. -
timeout
: The maximum length of an HTTP request in seconds. Defaults to 3. -
connect_timeout
: The maximum number of seconds to wait while trying to connect to a server. Defaults to 3. -
cache
: An optional implementation of Guzzle's CacheStorageInterface. Defaults to an in-memory cache. -
send_events
: If set to false, disables the sending of events to LaunchDarkly. Defaults to true. -
logger
: An optional implementation of Psr\Log\LoggerInterface. Defaults to a Monolog\Logger sending all messages to the PHP error_log. -
offline
: If set to true, disables all network calls and always returns the default value for flags. Defaults to false. -
feature_requester
: An optional FeatureRequester implementation, or a class or factory for one. Defaults to Guzzle::featureRequester(). There are also optional packages providing database integrations; see Storing data. -
feature_requester_class
: Deprecated, equivalent to feature_requester. -
event_publisher
: An optional EventPublisher implementation, or a class or factory for one. Defaults to Curl::eventPublisher(). -
event_publisher_class
: Deprecated, equivalent to event_publisher. -
all_attributes_private
: If set to true, no user attributes (other than the key) will be sent back to LaunchDarkly. Defaults to false. -
private_attribute_names
: An optional array of user attribute names to be marked private. Any users sent to LaunchDarkly with this configuration active will have attributes with these names removed. You can also set private attributes on a per-user basis in LDUserBuilder. - Other options may be available depending on any features you are using from the
LaunchDarkly\Integrations
namespace.
-
Return values
LDClient —alias()
Associates two users for analytics purposes.
public
alias(LDUser $user, LDUser $previousUser) : void
This can be helpful in the situation where a person is represented by multiple LaunchDarkly users. This may happen, for example, when a person initially logs into an application-- the person might be represented by an anonymous user prior to logging in and a different user after logging in, as denoted by a different user key.
Parameters
Return values
void —allFlagsState()
Returns an object that encapsulates the state of all feature flags for a given user.
public
allFlagsState(LDUser $user[, array<string|int, mixed> $options = [] ]) : FeatureFlagsState
This includes the flag values as well as other flag metadata that may be needed by front-end code, since the most common use case for this method is bootstrapping in conjunction with the JavaScript browser SDK.
This method does not send analytics events back to LaunchDarkly.
Parameters
- $user : LDUser
-
The end user requesting the feature flags
- $options : array<string|int, mixed> = []
-
Optional properties affecting how the state is computed:
-
clientSideOnly
: Set this to true to specify that only flags marked for client-side use should be included; by default, all flags are included -
withReasons
: Set this to true to include evaluation reasons (see LDClient::variationDetail()) -
detailsOnlyForTrackedFlags
: Set to true to omit any metadata that is normally only used for event generation, such as flag versions and evaluation reasons, unless the flag has event tracking or debugging turned on
-
Return values
FeatureFlagsState —a FeatureFlagsState object (will never be null)
flush()
Publishes any pending analytics events to LaunchDarkly.
public
flush() : bool
This is normally done automatically by the SDK.
Return values
bool —Whether the events were successfully published
identify()
Reports details about a user.
public
identify(LDUser $user) : void
This simply registers the given user properties with LaunchDarkly without evaluating a feature flag. This also happens automatically when you evaluate a flag.
Parameters
- $user : LDUser
-
The user properties
Return values
void —isOffline()
Returns whether the LaunchDarkly client is in offline mode.
public
isOffline() : bool
Return values
bool —secureModeHash()
Generates an HMAC sha256 hash for use in Secure mode.
public
secureModeHash(LDUser $user) : string
See: Secure mode
Parameters
- $user : LDUser
Return values
string —track()
Tracks that a user performed an event.
public
track(string $eventName, LDUser $user[, mixed $data = null ][, numeric $metricValue = null ]) : void
Parameters
- $eventName : string
-
The name of the event
- $user : LDUser
-
The user that performed the event
- $data : mixed = null
-
Optional additional information to associate with the event
- $metricValue : numeric = null
-
A numeric value used by the LaunchDarkly experimentation feature in numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This field will also be returned as part of the custom event for Data Export.
Return values
void —variation()
Calculates the value of a feature flag for a given user.
public
variation(string $key, LDUser $user[, mixed $default = false ]) : mixed
Parameters
- $key : string
-
The unique key for the feature flag
- $user : LDUser
-
The end user requesting the flag
- $default : mixed = false
-
The default value of the flag
Return values
mixed —The result of the Feature Flag evaluation, or $default if any errors occurred.
variationDetail()
Calculates the value of a feature flag, and returns an object that describes the way the value was determined.
public
variationDetail(string $key, LDUser $user[, mixed $default = false ]) : EvaluationDetail
The "reason" property in the result will also be included in analytics events, if you are capturing detailed event data for this flag.
Parameters
- $key : string
-
The unique key for the feature flag
- $user : LDUser
-
The end user requesting the flag
- $default : mixed = false
-
The default value of the flag
Return values
EvaluationDetail —An EvaluationDetail object that includes the feature flag value and evaluation reason.