LaunchDarkly PHP SDK 6.1.0

LDContextMultiBuilder
in package

A mutable object that uses the builder pattern to specify properties for a multi-context.

Use this builder if you need to construct an LDContext that contains multiple contexts, each for a different context kind. To define a regular context for a single kind, use LDContext::create() or LDContext::builder().

Obtain an instance of LDContextMultiBuilder by calling LDContext::multiBuilder(); then, call LDContextMultiBuilder::add() to specify the individual context for each kind. The method returns a reference to the same builder, so calls can be chained:

    $context = LDContext::multiBuilder()
      ->add(LDContext::create('my-user-key'))
      ->add(LDContext::create('my-org-key', 'organization'))
      ->build();
Tags
see
LDContext

Table of Contents

add()  : LDContextMultiBuilder
Adds an individual LDContext for a specific kind to the builer.
build()  : LDContext
Creates an LDContext from the current builder properties.

Methods

add()

Adds an individual LDContext for a specific kind to the builer.

public add(LDContext $context) : LDContextMultiBuilder

It is invalid to add more than one LDContext for the same kind, or to add an LDContext that is itself invalid. This error is detected when you call LDContextMultiBuilder::build().

If the nested context is a multi-context, this is exactly equivalent to adding each of the individual contexts from it separately. For instance, in the following example, $multi1 and $multi2 end up being exactly the same:

    $c1 = LDContext::create('key1', 'kind1');
    $c2 = LDContext::create('key2', 'kind2');
    $c3 = LDContext::create('key3', 'kind3');'

    $multi1 = LDContext::multiBuilder()->add($c1)->add($c2)->add($c3).build();

    $c1plus2 = LDContext::multiBuilder()->add($c1)->add($c2).build();
    $multi2 = LDContext::multiBuilder()->add($c1plus2)->add($c3)->build();
Parameters
$context : LDContext

the context to add

Return values
LDContextMultiBuilder

the builder

build()

Creates an LDContext from the current builder properties.

public build() : LDContext

The LDContext is immutable and will not be affected by any subsequent actions on the builder.

It is possible for an LDContextMultiBuilder to represent an invalid state. Instead of throwing an exception, the LDContextMultiBuilder always returns an LDContext, and you can check LDContext::isValid() or LDContext::getError() to see if it has an error. See LDContext::isValid() for more information about invalid context conditions. If you pass an invalid context to an SDK method, the SDK will detect this and will log a description of the error.

If only one context was added to the builder, this method returns that context rather than a multi-context.

Return values
LDContext

a new LDContext

Search results