diff --git a/README.md b/README.md index 1fd8111..36695a5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Flagsmith PHP SDK requires the following PHP extensions to be enabled. These - bc-math - gmp -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. +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). ## Local Evaluation diff --git a/examples/.env.sample b/examples/.env.sample deleted file mode 100644 index c76d32b..0000000 --- a/examples/.env.sample +++ /dev/null @@ -1 +0,0 @@ -API_KEY=API_KEY \ No newline at end of file diff --git a/examples/Dockerfile b/examples/Dockerfile deleted file mode 100644 index 1918145..0000000 --- a/examples/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM php:7.4-cli - -RUN apt-get update && \ - apt-get install -y software-properties-common - -RUN apt-get update && apt-get install -y \ - git \ - zip \ - curl \ - sudo \ - unzip \ - libzip-dev \ - libicu-dev \ - libbz2-dev \ - libpng-dev \ - libjpeg-dev \ - libmcrypt-dev \ - libreadline-dev \ - libfreetype6-dev \ - libxml2-dev \ - libgmp-dev \ - g++ - -COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer - -RUN docker-php-ext-install bcmath - -RUN docker-php-ext-install gmp - -WORKDIR /var/code - - -CMD ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index 7d16970..0000000 --- a/examples/README.md +++ /dev/null @@ -1,81 +0,0 @@ - - -# Flagsmith PHP Example - -This example uses the following packages to invoke Flagsmith APIs. -- Nyholm/PSR7 -- Symfony/HTTP-client -- PHP-HTTP/httplug -- Slim micro framework -- Slim-twig - -## Steps -```sh -rm -rf ./vendor/ -composer clear-cache -composer install -php index.php -php -S 0.0.0.0:8000 -``` - -Returns a response of all the flags present. - -More examples will be added for all methods and endpoints. - -# Docker - -The following steps can be used to run the files in a docker container. - -Note: Please copy .env.sample as .env and replace the API key in the .env file. - -```sh -docker-compose up -d -docker exec -it example-app sh -c "rm -rf ./vendor/" -docker exec -it example-app composer clear-cache -docker exec -it example-app composer install -docker exec -it example-app php -S 0.0.0.0:8000 -``` - -# Reduce Flagsmith calls with local evaluation - -You can reduce network calls by using local evaluations. - -```php -$flagsmith = (new Flagsmith(TOKEN)); -// This will load the environment from cache (or API, if cache does not exist.) -$flagsmith->updateEnvironment(); -``` - - It is recommended to use a psr simple-cache implementation to cache the environment document between multiple requests. - -```sh -composer require symfony/cache -``` - -```php -$flagsmith = (new Flagsmith(TOKEN)) - ->withCache(new Psr16Cache(new FilesystemAdapter())); -// Cache the environment call to reduce network calls for each and every evaluation. -// This will load the environment from cache (or API, if cache does not exist.) -$flagsmith->updateEnvironment(); -``` - -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. - -```php -// the environment will be cached for 100 seconds. -$flagsmith = $flagsmith->withEnvironmentTtl(100); -$flagsmith->updateEnvironment(); -``` - -```sh -* * * 1 40 php index.php # using cli -* * * 1 40 curl http://localhost:8000/ # using http -``` - -Note: -- Please note that for the environment cache, please use the server key generated from the Flagsmith Settings menu. The key's prefix is `ser.`. -- 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. - -## Troubleshooting -If you see dependency related issues. Try backing up and removing your composer.lock file and then running composer install diff --git a/examples/composer.json b/examples/composer.json deleted file mode 100644 index f1c4bfc..0000000 --- a/examples/composer.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "require": { - "nyholm/psr7": "^1.5", - "flagsmith/flagsmith-php-client": "dev-main", - "symfony/http-client": "^5.4", - "php-http/httplug": "^2.2", - "symfony/cache": "^5.4", - "slim/slim": "4.*", - "slim/twig-view": "^3.3", - "nyholm/psr7-server": "^1.0", - "php-http/cache-plugin": "^1.7" - }, - "config": { - "allow-plugins": { - "php-http/discovery": true - } - } -} diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml deleted file mode 100644 index 8e0faab..0000000 --- a/examples/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: "3" - -services: - app: - container_name: example-app - build: ./ - environment: - API_KEY: ${API_KEY} - ports: - - 8000:8000 - volumes: - - ./:/var/code - command: tail -f /dev/null diff --git a/examples/index.php b/examples/index.php deleted file mode 100644 index 2be6539..0000000 --- a/examples/index.php +++ /dev/null @@ -1,51 +0,0 @@ -withDefaultFlagHandler(function ($featureName) { - $defaultFlag = (new DefaultFlag()) - ->withEnabled(false)->withValue(null); - if ($featureName === 'secret_button') { - return $defaultFlag->withValue('{"colour": "#ababab"}'); - } - - return $defaultFlag; - }); - -$featureName = 'secret_button'; - -// Create App -$app = AppFactory::create(); - -// Create Twig -$twig = Twig::create(__DIR__ . '/templates', ['cache' => false]); - -// Add Twig-View Middleware -$app->add(TwigMiddleware::create($app, $twig)); -$app->addErrorMiddleware(true, true, true); - -$app->get('/', function ($request, $response, $args) use ($flagsmith, $featureName) { - $queryParams = $request->getQueryParams(); - $flags = $flagsmith->getIdentityFlags(($queryParams['identifier'] ?? '')); - - $view = Twig::fromRequest($request); - return $view->render($response, 'index.html', [ - 'identifier' => $queryParams['identifier'] ?? null, - 'traitname' => $queryParams['traitname'] ?? null, - 'traitvalue' => $queryParams['traitvalue'] ?? null, - 'font_colour' => json_decode($flags->getFeatureValue($featureName) ?? '{"colour": "#ababab"}'), - 'enabled' => $flags->isFeatureEnabled($featureName) - ]); -})->setName('profile'); - -// Run app -$app->run(); diff --git a/examples/templates/index.html b/examples/templates/index.html deleted file mode 100644 index cb0dde6..0000000 --- a/examples/templates/index.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Flagsmith Test - - - - -

- Hello {{ identifier|default('World!') }}, -

- {% if enabled %} - -{% endif %} -

-

-

Identify as a user

- - -
-

... with an optional user trait

- -
- - -
- - -
-

- - -