fromEnvironment

Learn how to create the SDK from environment variables.

This static factory method creates an SDK instance from the CROCT_* environment variables, so you do not have to hard-code credentials.

Signature

This method has the following signature:

public static function fromEnvironment(?IdentityStore $storage = null): self

This method returns a configured SDK instance.

Example

Here is a basic example of how to use this method:

1234
<?phpuse Croct\Plug\Croct;
$croct = Croct::fromEnvironment();

Environment variables

The method reads the following variables:

VariableRequiredDescription
CROCT_APP_IDYesThe ID of the application.
CROCT_API_KEYYesThe API key used to authenticate requests.
CROCT_TOKEN_DURATIONNoThe lifetime of the user token, in seconds.
CROCT_BASE_ENDPOINT_URLNoThe base URL to use for the API calls.

Parameters

The following list describes the supported parameters:

storage(optional)

The storage that persists the visitor session.

The default is null, which uses a cookie-based store.

Default:null