Skip to main content

DevCycle PHP Server SDK

Welcome to the the DevCycle PHP SDK, initially generated via the DevCycle Bucketing API.

The SDK is available as a package on Packagist. It is also open source and can be viewed on Github.

Packagist GitHub

Requirements

PHP 7.3 and later.

Installation

Composer Installation

To install the bindings via Composer, add the following to composer.json:

{
"require": {
"devcycle/php-server-sdk": "*"
}
}

Then run composer install

Manual Installation

Download the files and include autoload.php:

<?php
require_once('/path/to/DevCycle/vendor/autoload.php');

Getting Started

Please follow the installation procedure and then run the following:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: bearerAuth
$config = DevCycle\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');

$apiInstance = new DevCycle\Api\DVCClient(
$config,
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
);
$user_data = new \DevCycle\Model\UserData(array(
"user_id"=>"my-user"
)); // \DevCycle\Model\UserData

try {
$result = $apiInstance->allFeatures($user_data);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DVCClient->allFeatures: ', $e->getMessage(), PHP_EOL;
}

Usage

Get and use Variable by key

try {
$result = $apiInstance->variable($user_data, "my-key", "default");
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DVCClient->variable: ', $e->getMessage(), PHP_EOL;
}

See getVariableByKey on the Bucketing API for the variable response format.

Get all Variables

try {
$result = $apiInstance->allVariables($user_data);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DVCClient->allVariables: ', $e->getMessage(), PHP_EOL;
}

See getVariables on the Bucketing API for the variable response format.

Getting all Features

try {
$result = $apiInstance->allFeatures($user_data);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DVCClient->allFeatures: ', $e->getMessage(), PHP_EOL;
}

See getFeatures on the Bucketing API for the feature response format.

Track Event

$event_data = new \DevCycle\Model\Event(array(
"type"=>"my-event"
));

try {
$result = $apiInstance->track($user_data, $event_data);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DVCClient->track: ', $e->getMessage(), PHP_EOL;
}

EdgeDB

EdgeDB allows you to save user data to our EdgeDB storage so that you don't have to pass in all the user data every time you identify a user. Read more about EdgeDB.

To get started, contact us at [email protected] to enable EdgeDB for your project.

Once you have EdgeDB enabled in your project, pass in the enableEdgeDB option to turn on EdgeDB mode for the SDK:

$config = DevCycle\Configuration::getDefaultConfiguration()->setApiKey('Authorization', '<INSERT SDK KEY>');
$options = new DevCycle\DVCOptions(true);
$apiInstance = new DevCycle\Api\DVCClient(
$config,
dvcOptions:$options
);

Async Methods

Each method in the Usage section has a corresponding asynchronous method:

    $result = $apiInstance->allVariables($user_data);
$apiInstance->allVariablesAsync($user_data)->then(function($result) {
print_r($result);
});

Models

UserData

User data is provided to most SDK requests to identify the user / context of the feature evaluation

NameTypeDescriptionNotes
user_idStringUnique id to identify the user
emailStringUser's email used to identify the user on the dashboard / target audiences[optional]
nameStringUser's name used to identify the user on the dashboard / target audiences[optional]
languageStringUser's language in ISO 639-1 format[optional]
countryStringUser's country in ISO 3166 alpha-2 format[optional]
app_versionStringApp Version of the running application[optional]
app_buildStringApp Build number of the running application[optional]
custom_dataObjectUser's custom data to target the user with, data will be logged to DevCycle for use in dashboard.[optional]
private_custom_dataObjectUser's custom data to target the user with, data will not be logged to DevCycle only used for feature bucketing.[optional]
created_dateFloatDate the user was created, Unix epoch timestamp format[optional]
last_seen_dateFloatDate the user was created, Unix epoch timestamp format[optional]
platformStringPlatform the Client SDK is running on[optional]
platform_versionStringVersion of the platform the Client SDK is running on[optional]
device_modelStringUser's device model[optional]
sdk_typeStringDevCycle SDK type[optional]
sdk_versionStringDevCycle SDK Version[optional]

Event

Event data is provided to track calls to log events to DevCycle

NameTypeDescriptionNotes
typeStringCustom event type
targetStringCustom event target / subject of event. Contextual to event type[optional]
dateFloatUnix epoch time the event occurred according to client[optional]
valueFloatValue for numerical events. Contextual to event type[optional]
meta_dataObjectExtra JSON metadata for event. Contextual to event type[optional]

Variable

Variable objects are returned by the SDK when calling variable or allVariables.

NameTypeDescriptionNotes
_idStringunique database id
keyStringUnique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
typeStringVariable type
valueObjectVariable value can be a string, number, boolean, or JSON

Feature

Feature objects are returned by the SDK when calling allFeatures

NameTypeDescriptionNotes
_idStringunique database id
keyStringUnique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
typeStringFeature type
_variationStringBucketed feature variation
eval_reasonStringEvaluation reasoning[optional]

Tests

To run the tests, use:

composer install
vendor/bin/phpunit

About this package

This PHP package is automatically generated by the OpenAPI Generator project:

  • API version: 1.0.0
  • Package version: 1.0.3
  • Build package: org.openapitools.codegen.languages.PhpClientCodegen