Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Niko/PHP-Docs-to-new-template #552

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nikomancy
Copy link
Contributor

What

Updated the PHP docs to follow a similar template to the node docs.

Why?

  • The goal is to make the learning journey for engineers working with specific SDKs easier.
  • Content is easier to find in the TOC improving navigability.
  • Code samples for typed examples have been added for ease of use.
  • Boilerplate prose docs have been added to allow engineers to learn about relevant conceptual information along side the code without having to context switch to other parts of the docs.

Review Instructions

  • Due to me not knowing PHP, we are missing code samples for bandits.
  • All net new code samples in this are untested and need to be validated by someone who actually knows PHP.

Todo before merge

  • Add bandit code samples
  • Update redirects
  • Delete php.md file

Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for eppo-data-docs ready!

Name Link
🔨 Latest commit 9105887
🔍 Latest deploy log https://app.netlify.com/sites/eppo-data-docs/deploys/675fc6c272fff900084e9935
😎 Deploy Preview https://deploy-preview-552--eppo-data-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@typotter typotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Niko,
Thanks for reorganizing our docs! I know there's a lot (and all written by different people). Big undertaking 💪

I apologize that the docs you had to start with were out of date. When the PHP SDK was last touched, the updated APIs were captured only in the repository's README and EppoClient.php

I copied over a number of code samples as suggestions you should hopefully be able to just drop in.

---
import FeatureCard from '/src/components/FeatureCard';

The Eppo PHP SDK allows you to manage feature flags and experiments in your PHP applications.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDKs allow developers to use feature flags and experiments within their applications. "manage" implies being able to edit or make changes to the flags.

Comment on lines +25 to +30
$eppoClient = EppoClient::init(
"<your_sdk_key>",
"<base_url>", // optional, default https://eppo.cloud/api
$assignmentLogger, // optional, must be an instance of Eppo\LoggerInterface
$cache // optional, must be an instance of PSR-6 CacheInterface. If not passed, FileSystem cache will be used
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$eppoClient = EppoClient::init(
"<your_sdk_key>",
"<base_url>", // optional, default https://eppo.cloud/api
$assignmentLogger, // optional, must be an instance of Eppo\LoggerInterface
$cache // optional, must be an instance of PSR-6 CacheInterface. If not passed, FileSystem cache will be used
);
$eppoClient = EppoClient::init(
'<your_api_key>',
'<base_url>', // optional, default https://fscdn.eppo.cloud/api
$assignmentLogger, // optional, must be an instance of Eppo\Logger\LoggerInterface
$cache // optional, must be an instance of PSR-16 SimpleCache\CacheInterface. If not passed, FileSystem cache will be used
$httpClient // optional, must be an instance of PSR-18 ClientInterface. If not passed, Discovery will be used to find a suitable implementation
$requestFactory // optional, must be an instance of PSR-17 Factory. If not passed, Discovery will be used to find a suitable implementation
);

Comment on lines +38 to +43
$subjectAttributes = [];
$variation = $eppoClient->getStringAssignment('subject-1', 'experiment_5', $subjectAttributes);

if ($variation === 'control') {
// do something
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$subjectAttributes = [];
$variation = $eppoClient->getStringAssignment('subject-1', 'experiment_5', $subjectAttributes);
if ($variation === 'control') {
// do something
}
$subjectAttributes = [ 'tier' => 2 ];
$assignment = $eppoClient->getStringAssignment('experimentalBackground', 'user123', $subjectAttributes, 'control');
if ($assignment !== 'control') {
// do something special
} else {
// Show the default treatment
}


## Experiments

For experiments, you'll need to implement logging. Here's a basic example:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Eppo\Logger\LoggerInterface;

class Logger implements LoggerInterface {
public function logAssignment(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logAssignment just takes an AssignmentEvent parameter (see example above). The AssignmentEvent class has the following shape

        public string $experiment,
        public string $variation,
        public string $allocation,
        public string $featureFlag,
        public string $subject,
        public float $timestamp,
        public array $subjectAttributes = [],
        public array $sdkMetadata = [],
        public array $extraLogging = []

Comment on lines +115 to +121
public function logAssignment(
string $experiment,
string $variation,
string $subject,
string $timestamp,
array $subjectAttributes = []
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function logAssignment(
string $experiment,
string $variation,
string $subject,
string $timestamp,
array $subjectAttributes = []
) {
public function logAssignment(AssignmentEvent $assignmentEvent) {

}
```

The logger receives these parameters:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may take up to 10 seconds for changes to Eppo experiments to be reflected by the SDK assignments.
:::

## Assignment Logger Schema
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to schema in AssignmentEvent

Comment on lines +41 to +44
getBooleanAssignment(...)
getNumericAssignment(...)
getJSONStringAssignment(...)
getParsedJSONAssignment(...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getBooleanAssignment(...)
getNumericAssignment(...)
getJSONStringAssignment(...)
getParsedJSONAssignment(...)
getBooleanAssignment(...)
getNumericAssignment(...)
getIntegerAssignment(...)
getStringAssignment(...)
getJSONAssignment(...)


### Logging Examples

[Placeholder: Need PHP-specific examples for logging to different services (Segment, Rudderstack, mParticle, Snowplow)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants