Skip to content

Commit 218ce80

Browse files
authored
Merge pull request #19 from Flagsmith/release/3.0.0
Release 3.0.0
2 parents 7f8c19c + 54676f1 commit 218ce80

File tree

84 files changed

+6025
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+6025
-483
lines changed

.github/workflows/pull-requests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ jobs:
2020
steps:
2121
- name: Cloning repo
2222
uses: actions/checkout@v2
23-
# with:
24-
# fetch-depth: 0
25-
# submodules: recursive
23+
with:
24+
fetch-depth: 0
25+
submodules: recursive
2626

2727
- name: Setup PHP
2828
uses: shivammathur/setup-php@v2
2929
with:
3030
version: '{{ matrix.php-version }}'
3131
tools: php-cs-fixer, phpunit
32+
extensions: "bcmath, gmp"
3233

3334
- name: Get composer cache directory
3435
id: composer-cache

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor
22
package-lock.json
33
composer.lock
4-
/node_modules/
4+
/node_modules/
5+
.env

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tests/Engine/EngineTests/EngineTestData"]
2+
path = tests/Engine/EngineTests/EngineTestData
3+
url = [email protected]:Flagsmith/engine-test-data.git

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
1010
The SDK for PHP applications for [https://www.flagsmith.com/](https://www.flagsmith.com/).
1111

12+
## Requirements
13+
14+
The Flagsmith PHP SDK requires the following PHP extensions to be enabled. These are essentials for the library to function properly.
15+
16+
- bc-math
17+
- gmp
18+
19+
Please view the documentation here to install the extensions, if you haven't already. For [BC-Math](https://www.php.net/manual/en/bc.installation.php) and [GMP](https://www.php.net/manual/en/gmp.installation.php). To enable for docker containers, please have a look at our sample in the example directory.
20+
21+
## Local Evaluation
22+
23+
Since PHP requests are separate, there is little benefit to use local evaluation without caching. To enable local evaluation, please set the environmentTtl value (>0) and using PSR simple cache implementation.
24+
1225
## Adding to your project
1326

1427
For full documentation visit [https://docs.flagsmith.com/clients/php/](https://docs.flagsmith.com/clients/php/)

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "flagsmith/flagsmith-php-client",
33
"type": "library",
4+
"version": "3.0.0",
45
"license": "BSD-3-Clause",
56
"authors": [
67
{
@@ -20,11 +21,14 @@
2021
"guzzlehttp/guzzle": "^7.3",
2122
"guzzlehttp/psr7": "^2.1.0",
2223
"phpunit/phpunit": "^9.5",
23-
"friendsofphp/php-cs-fixer": "^3.6"
24+
"symfony/cache": "^5.4.6",
25+
"friendsofphp/php-cs-fixer": "^3.6",
26+
"doppiogancio/mocked-client": "^3.0"
2427
},
2528
"autoload": {
2629
"psr-4": {
27-
"Flagsmith\\": "src"
30+
"Flagsmith\\": "src",
31+
"FlagsmithTest\\": "tests"
2832
}
2933
}
3034
}

examples/.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_KEY=API_KEY

examples/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ RUN apt-get update && apt-get install -y \
1818
libreadline-dev \
1919
libfreetype6-dev \
2020
libxml2-dev \
21+
libgmp-dev \
2122
g++
2223

2324
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
2425

26+
RUN docker-php-ext-install bcmath
27+
28+
RUN docker-php-ext-install gmp
29+
2530
WORKDIR /var/code
2631

32+
2733
CMD ["tail", "-f", "/dev/null"]

examples/README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ This example uses the following packages to invoke Flagsmith APIs.
66
- Nyholm/PSR7
77
- Symfony/HTTP-client
88
- PHP-HTTP/httplug
9+
- Slim micro framework
10+
- Slim-twig
911

1012
## Steps
1113
```sh
14+
rm -rf ./vendor/
15+
composer clear-cache
1216
composer install
1317
php index.php
18+
php -S 0.0.0.0:8000
1419
```
1520

1621
Returns a response of all the flags present.
@@ -21,11 +26,56 @@ More examples will be added for all methods and endpoints.
2126

2227
The following steps can be used to run the files in a docker container.
2328

29+
Note: Please copy .env.sample as .env and replace the API key in the .env file.
30+
2431
```sh
2532
docker-compose up -d
26-
docker exec -it app composer install
27-
docker exec -it app index.php
33+
docker exec -it example-app sh -c "rm -rf ./vendor/"
34+
docker exec -it example-app composer clear-cache
35+
docker exec -it example-app composer install
36+
docker exec -it example-app php -S 0.0.0.0:8000
37+
```
38+
39+
# Reduce Flagsmith calls with local evaluation
40+
41+
You can reduce network calls by using local evaluations.
42+
43+
```php
44+
$flagsmith = (new Flagsmith(TOKEN));
45+
// This will load the environment from cache (or API, if cache does not exist.)
46+
$flagsmith->updateEnvironment();
47+
```
48+
49+
It is recommended to use a psr simple-cache implementation to cache the environment document between multiple requests.
50+
51+
```sh
52+
composer require symfony/cache
2853
```
2954

55+
```php
56+
$flagsmith = (new Flagsmith(TOKEN))
57+
->withCache(new Psr16Cache(new FilesystemAdapter()));
58+
// Cache the environment call to reduce network calls for each and every evaluation.
59+
// This will load the environment from cache (or API, if cache does not exist.)
60+
$flagsmith->updateEnvironment();
61+
```
62+
63+
An optional cron job can be added to refresh this cache at a set time depending on your choice. Please set EnvironmentTTL value for this purpose.
64+
65+
```php
66+
// the environment will be cached for 100 seconds.
67+
$flagsmith = $flagsmith->withEnvironmentTtl(100);
68+
$flagsmith->updateEnvironment();
69+
```
70+
71+
```sh
72+
* * * 1 40 php index.php # using cli
73+
* * * 1 40 curl http://localhost:8000/ # using http
74+
```
75+
76+
Note:
77+
- Please note that for the environment cache, please use the server key generated from the Flagsmith Settings menu. The key's prefix is `ser.`.
78+
- The cache is important for concurrent requests. Without cache, each request in PHP is a different process with its own memory objects. The cache (filesystem or other) would enforce that the network call is reduced to a file system one.
79+
3080
## Troubleshooting
3181
If you see dependency related issues. Try backing up and removing your composer.lock file and then running composer install

examples/composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
22
"require": {
3-
"nyholm/psr7": "1.4.1",
4-
"flagsmith/flagsmith-php-client": "^2.1",
3+
"nyholm/psr7": "^1.5",
4+
"flagsmith/flagsmith-php-client": "dev-main",
55
"symfony/http-client": "^5.4",
6-
"php-http/httplug": "^2.2"
6+
"php-http/httplug": "^2.2",
7+
"symfony/cache": "^5.4",
8+
"slim/slim": "4.*",
9+
"slim/twig-view": "^3.3",
10+
"nyholm/psr7-server": "^1.0",
11+
"php-http/cache-plugin": "^1.7"
712
}
813
}

examples/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ version: "3"
22

33
services:
44
app:
5-
container_name: app
5+
container_name: example-app
66
build: ./
7+
environment:
8+
API_KEY: ${API_KEY}
9+
ports:
10+
- 8000:8000
711
volumes:
812
- ./:/var/code
913
command: tail -f /dev/null

0 commit comments

Comments
 (0)