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

[FSSDK-9630] Fix: Code examples #273

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,55 @@ php composer.phar require optimizely/optimizely-sdk
Create the Optimizely client, for example:

```php
<?php
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved

use Optimizely\Optimizely;
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved

$optimizely = new Optimizely(<<DATAFILE>>);
```

Or you may also use OptimizelyFactory method to create an optimizely client using your SDK key, an optional fallback datafile and an optional datafile access token. Using this method internally creates an HTTPProjectConfigManager. See [HTTPProjectConfigManager](#use-httpprojectconfigmanager) for further detail.

```php
$optimizelyClient = OptimizelyFactory::createDefaultInstance("your-sdk-key", <<DATAFILE>>, <<DATAFILE_AUTH_TOKEN>>);
<?php

use Optimizely\OptimizelyFactory;

$optimizelyClient = OptimizelyFactory::createDefaultInstance(
"your-sdk-key",
<<DATAFILE>>,
<<DATAFILE_AUTH_TOKEN>>
);
```
To access your HTTPProjectConfigManager:

```php
<?php

use Optimizely\Optimizely;

/** @var Optimizely $optimizelyClient */
$configManager = $optimizelyClient->configManager;
```

Or you can also provide an implementation of the [`ProjectConfigManagerInterface`](https://github.com/optimizely/php-sdk/blob/master/src/Optimizely/ProjectConfigManager/ProjectConfigManagerInterface.php) in the constructor:

```php
<?php

use Optimizely\Optimizely;
use Optimizely\ProjectConfigManager\HTTPProjectConfigManager;

$configManager = new HTTPProjectConfigManager(<<SDK_KEY>>);
$optimizely = new Optimizely(<<DATAFILE>>, null, null, null, false, null, $configManager);
$optimizely = new Optimizely(
<<DATAFILE>>,
null,
null,
null,
false,
null,
$configManager
);
```

### ProjectConfigManagerInterface
Expand All @@ -74,6 +104,10 @@ Calling `fetch` will update the internal ProjectConfig instance that will be ret
### Use HTTPProjectConfigManager

```php
<?php

use Optimizely\ProjectConfigManager\HTTPProjectConfigManager;

$configManager = new HTTPProjectConfigManager(<<SDK_KEY>>);
```

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"require": {
"php": ">=8.1",
"guzzlehttp/guzzle": ">=6.2",
"justinrainbow/json-schema": "^1.6 || ^2.0 || ^4.0 || ^5.0",
"lastguest/murmurhash": "^1.3.0",
"guzzlehttp/guzzle": ">=6.2",
"monolog/monolog": ">=1.21"
},
"require-dev": {
Expand All @@ -31,5 +31,8 @@
"psr-4": {
"Optimizely\\": "src/Optimizely"
}
},
"config": {
"sort-packages": true
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Optimizely/Decide/OptimizelyDecision.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function getReasons()
return $this->reasons;
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getKey()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyAudience.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getConditions()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function getEvents()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getExperimentIds()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyExperiment.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function getVariationsMap()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function getVariablesMap()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function getValue()
/**
* @return string JSON representation of the object.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyVariation.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function getVariablesMap()
* @return string JSON representation of the object.
* Unsets featureEnabled property for variations of ab experiments.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$props = get_object_vars($this);
Expand Down
Loading