LaunchDarkly PHP SDK 3.7.1

LDClient

A client for the LaunchDarkly API.

Table of Contents

DEFAULT_BASE_URI 'https://app.launchdarkly.com'
DEFAULT_EVENTS_URI 'https://events.launchdarkly.com'
VERSION The current SDK version. '3.7.1'
__construct() Creates a new client instance that connects to LaunchDarkly. LDClient
variation() Calculates the value of a feature flag for a given user. mixed
variationDetail() Calculates the value of a feature flag, and returns an object that describes the way the value was determined. EvaluationDetail
toggle() Deprecated name for variation(). mixed
isOffline() Returns whether the LaunchDarkly client is in offline mode. bool
track() Tracks that a user performed an event. void
identify() Reports details about a user. void
allFlags() Deprecated alternative to allFlagsState(). array|null
allFlagsState() Returns an object that encapsulates the state of all feature flags for a given user. FeatureFlagsState
secureModeHash() Generates an HMAC sha256 hash for use in Secure mode. string
flush() Publishes any pending analytics events to LaunchDarkly. bool

Constants

DEFAULT_BASE_URI

string $DEFAULT_BASE_URI = 'https://app.launchdarkly.com'

DEFAULT_EVENTS_URI

string $DEFAULT_EVENTS_URI = 'https://events.launchdarkly.com'

VERSION

The current SDK version.

string $VERSION = '3.7.1'

Methods

__construct()

Creates a new client instance that connects to LaunchDarkly.

public __construct( $sdkKey : string [, $options : array = array() ] ) : LDClient
Parameters
$sdkKey : string

The SDK key for your account

$options : array = array()

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.
  • 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 {@link \LaunchDarkly\FeatureRequester} implementation, or a class or factory for one. Defaults to {@link \LaunchDarkly\Integrations\Guzzle::featureRequester()}.
  • feature_requester_class: Deprecated, equivalent to feature_requester.
  • event_publisher: An optional {@link \LaunchDarkly\EventPublisher} implementation, or a class or factory for one. Defaults to {@link \LaunchDarkly\Integrations\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

variation()

Calculates the value of a feature flag for a given user.

public variation( $key : string , $user : LDUser [, $default : mixed = 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( $key : string , $user : LDUser [, $default : mixed = 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.

toggle()

Deprecated name for variation().

public toggle( $key : string , $user : LDUser [, $default : bool = false ] ) : mixed
Parameters
$key : string

The unique key for the feature flag

$user : LDUser

The end user requesting the flag

$default : bool = false

The default value of the flag

Tags
deprecated

Use variation() instead.

Return values
mixed

isOffline()

Returns whether the LaunchDarkly client is in offline mode.

public isOffline( ) : bool
Return values
bool

track()

Tracks that a user performed an event.

public track( $eventName : string , $user : LDUser [, $data : mixed = null ] [, $metricValue : number = 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 : number = 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.

identify()

Reports details about a user.

public identify( $user : LDUser ) : 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

allFlags()

Deprecated alternative to allFlagsState().

public allFlags( $user : LDUser ) : array|null

This returns an array mapping feature flag keys to their evaluated results for a given user.

If the result of a flag's evaluation would have returned the default variation, it will have a null entry. If the client is offline, has not been initialized, or a null user or user with null/empty user key, null will be returned. This method will not send analytics events back to LaunchDarkly.

The most common use case for this method is to bootstrap a set of client-side feature flags from a back-end service. Current versions of the JavaScript SDK require somewhat different data; for best compatibility, use allFlagsState() instead.

Parameters
$user : LDUser

The end user requesting the feature flags

Tags
deprecated

Use allFlagsState() instead. Current versions of the client-side SDK will not generate analytics events correctly if you pass the result of allFlags().

Return values
array|null

Mapping of feature flag keys to their evaluated results for $user

allFlagsState()

Returns an object that encapsulates the state of all feature flags for a given user.

public allFlagsState( $user : LDUser [, $options : array = array() ] ) : 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 = array()

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 {@link variationDetail()})
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

Search results