Skip to content

Commit

Permalink
[FSSDK-9630] Fix: Code examples (#281)
Browse files Browse the repository at this point in the history
* Fix: Add ReturnTypeWillChange attribute

* Enhancement: Keep packages sorted in composer.json

* Fix: Wrap arguments in code examples

* Fix: Code examples

---------

Co-authored-by: Andreas Möller <am@localheinz.com>
  • Loading branch information
mikechu-optimizely and localheinz authored Dec 4, 2023
1 parent 4963820 commit 8fe8574
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 4 deletions.
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

use Optimizely\Optimizely;

$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

0 comments on commit 8fe8574

Please sign in to comment.