fromDotenv
Learn how to create the SDK from a .env file.
This static factory method creates an SDK instance from a .env file, the simplest way to get started.
It reads the credentials from the CROCT_* variables in the .env file, falling back to the process environment, and uses a cookie-based session store, so there is nothing to wire up.
Signature
This method has the following signature:
public static function fromDotenv(?string $directory = null, ?IdentityStore $storage = null): selfThis 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::fromDotenv();Environment variables
The method reads the following variables:
| Variable | Required | Description |
|---|---|---|
| CROCT_APP_ID | Yes | The ID of the application. |
| CROCT_API_KEY | Yes | The API key used to authenticate requests. |
| CROCT_TOKEN_DURATION | No | The lifetime of the user token, in seconds. |
| CROCT_BASE_ENDPOINT_URL | No | The base URL to use for the API calls. |
Parameters
The following list describes the supported parameters: