Skip to content

Commit

Permalink
Config v6 (#44)
Browse files Browse the repository at this point in the history
* Add VSCode devenv configuration

* Run tests on PHP 8.3

* Update config JSON model to v6 + fix inconsistent error 1000 reporting + improve config json deserialization error reporting

* Refactor evaluator and evaluation logging to prepare it for the new features

* Implement new comparison operators

* Implement segment condition evaluation

* Implement prerequisite flag condition evaluation

* Implement SDK key format validation + fix broken tests

* Rename EvaluationDetails.getMatched* properties

* Improve message of error 1103

* Add matrix tests

* Align config json error handling of EvaluateLogBuilder with error reporting of RolloutEvaluator

* Add exception to the log format in DefaultLogger

* Add tests for evaluation logging + minor fixes

* Add User Object tests

* Add tests for sdk key format validation

* Add user attribute conversion tests + re-implement Utils.numberToString as NumberFormatter requires a PHP extension

* Add comparison attribute and comparison value trimming tests

* Add special character tests

* Add tests for EvaluationDetails.getMatchedTargetingRule/getMatchedPercentageOption properties

* Add flag overrides vs. prerequisite flags, config json salt and segments tests + add related exception object to EvaluationDetails

* Add override value type mismatch tests

* Bump version

* Update package version in samples

---------

Co-authored-by: Peter Adam Korodi <[email protected]>
  • Loading branch information
adams85 and kp-cat authored Mar 4, 2024
1 parent 7cb49a4 commit 60f4f5e
Show file tree
Hide file tree
Showing 144 changed files with 8,608 additions and 1,070 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1', '8.2' ]
php-versions: [ '8.1', '8.2', '8.3' ]
steps:
- uses: actions/checkout@v4

Expand Down
7 changes: 5 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

$finder = PhpCsFixer\Finder::create()
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

$config = (new PhpCsFixer\Config())
$config = (new Config())
->setRules([
'@PhpCsFixer' => true,
'@PSR2' => true,
Expand Down
21 changes: 21 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
// For intellisense and navigation in code:
"bmewburn.vscode-intelephense-client",

// For formatting and linting:
"junstyle.php-cs-fixer",
"SanderRonde.phpstan-vscode",

// For exploring and running tests:
"hbenl.vscode-test-explorer",
"recca0120.vscode-phpunit",

// For debugging:
"xdebug.php-debug" // to make this work, you need xdebug installed - see the description of the extension
],

// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// To debug tests, you need to launch this configuration first, then run the test to debug from the test explorer.
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003
}
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"intelephense.environment.phpVersion": "8.1.0",
// On Linux, replace "phpdebug.bat" with "XDEBUG_MODE=debug php".
// To make debugging work, you also need xdebug.start_with_request=yes in php.ini!
"phpunit.php": "phpdebug.bat",
"phpunit.args": [
"-c",
"phpunit.xml"
],
"php-cs-fixer.executablePath": "php-cs-fixer",
"php-cs-fixer.executablePathWindows": "${workspaceFolder}/vendor/bin/php-cs-fixer.bat",
"[php]": {
"editor.defaultFormatter": "junstyle.php-cs-fixer"
},
"phpstan.configFile": "phpstan.neon"
}
4 changes: 4 additions & 0 deletions phpdebug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
set XDEBUG_MODE=debug
php %*
2 changes: 1 addition & 1 deletion samples/consolesample/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"configcat/configcat-client": "^6",
"configcat/configcat-client": "^9",
"monolog/monolog": "^1.0"
}
}
2 changes: 1 addition & 1 deletion samples/laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "MIT",
"require": {
"php": "^7.2.5",
"configcat/configcat-client": "^6",
"configcat/configcat-client": "^9",
"fideloper/proxy": "^4.0",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0"
Expand Down
14 changes: 0 additions & 14 deletions src/Attributes/Config.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Attributes/PercentageAttributes.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Attributes/Preferences.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Attributes/RolloutAttributes.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Attributes/SettingAttributes.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Cache/ConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace ConfigCat\Cache;

use Exception;
use InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Throwable;

/**
* A cache API used to make custom cache implementations.
Expand All @@ -33,7 +33,7 @@ public function store(string $key, ConfigEntry $value): void

try {
$this->set($key, $value->serialize());
} catch (Exception $exception) {
} catch (Throwable $exception) {
$this->logger->error('Error occurred while writing the cache.', [
'event_id' => 2201, 'exception' => $exception,
]);
Expand Down Expand Up @@ -63,7 +63,7 @@ public function load(string $key): ConfigEntry
}

return ConfigEntry::fromCached($cached);
} catch (Exception $exception) {
} catch (Throwable $exception) {
$this->logger->error('Error occurred while reading the cache.', [
'event_id' => 2200, 'exception' => $exception,
]);
Expand Down
6 changes: 2 additions & 4 deletions src/Cache/ConfigEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ConfigCat\Cache;

use ConfigCat\ConfigJson\Config;
use UnexpectedValueException;

/**
Expand Down Expand Up @@ -79,10 +80,7 @@ public static function empty(): ConfigEntry

public static function fromConfigJson(string $configJson, string $etag, float $fetchTime): ConfigEntry
{
$deserialized = json_decode($configJson, true);
if (null == $deserialized) {
return self::empty();
}
$deserialized = Config::deserialize($configJson);

return new ConfigEntry($configJson, $deserialized, $etag, $fetchTime);
}
Expand Down
Loading

0 comments on commit 60f4f5e

Please sign in to comment.