Skip to content

Commit a2501e6

Browse files
authored
feat(validators-hook): created new package with validation offering (#30)
* feat(validators-hook): created new package with validation offering for OpenFeature hooks Signed-off-by: Tom Carrio <[email protected]> * ci: enable testing for Validators Signed-off-by: Tom Carrio <[email protected]> * ci: enable testing for DDTrace Signed-off-by: Tom Carrio <[email protected]>
1 parent a326c09 commit a2501e6

23 files changed

+675
-0
lines changed

.github/workflows/php-ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
php-version: ['7.4', '8.0', '8.1', '8.2']
1616
project-dir:
1717
- hooks/OpenTelemetry
18+
- hooks/DDTrace
19+
- hooks/Validators
1820
- providers/Flagd
1921
- providers/Split
2022
- providers/CloudBees

.gitsplit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ splits:
1010
target: "https://${GH_TOKEN}@github.com/open-feature-php/otel-hook.git"
1111
- prefix: "hooks/DDTrace"
1212
target: "https://${GH_TOKEN}@github.com/open-feature-php/dd-trace-hook.git"
13+
- prefix: "hooks/Validators"
14+
target: "https://${GH_TOKEN}@github.com/open-feature-php/validators-hook.git"
1315
- prefix: "providers/Flagd"
1416
target: "https://${GH_TOKEN}@github.com/open-feature-php/flagd-provider.git"
1517
- prefix: "providers/Split"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
name: Run Release Please
7+
jobs:
8+
release-please:
9+
runs-on: ubuntu-latest
10+
11+
# Release-please creates a PR that tracks all changes
12+
steps:
13+
- uses: google-github-actions/release-please-action@v3
14+
id: release
15+
with:
16+
command: manifest
17+
token: ${{secrets.GITHUB_TOKEN}}
18+
default-branch: main

hooks/Validators/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/composer.lock
2+
/vendor
3+
/build
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.0.1"
3+
}

hooks/Validators/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# OpenFeature Validator Hooks
2+
3+
[![a](https://img.shields.io/badge/slack-%40cncf%2Fopenfeature-brightgreen?style=flat&logo=slack)](https://cloud-native.slack.com/archives/C0344AANLA1)
4+
[![Latest Stable Version](http://poser.pugx.org/open-feature/validators-hook/v)](https://packagist.org/packages/open-feature/validators-hook)
5+
[![Total Downloads](http://poser.pugx.org/open-feature/validators-hook/downloads)](https://packagist.org/packages/open-feature/validators-hook)
6+
![PHP 7.4+](https://img.shields.io/badge/php->=7.4-blue.svg)
7+
[![License](http://poser.pugx.org/open-feature/validators-hook/license)](https://packagist.org/packages/open-feature/validators-hook)
8+
9+
## Overview
10+
11+
Validator Hook constructs that provide means to execute validation against resolved feature flag values.
12+
13+
This package also builds on various PSRs (PHP Standards Recommendations) such as the Logger interfaces (PSR-3) and the Basic and Extended Coding Standards (PSR-1 and PSR-12).
14+
15+
## Installation
16+
17+
```
18+
$ composer require open-feature/validators-hook // installs the latest version
19+
```
20+
21+
## Usage
22+
23+
The following validator hook constructs are available, but more are being worked on over time:
24+
25+
- `RegexpValidatorHoook`
26+
27+
28+
```php
29+
use OpenFeature\Hooks\Validators\RegexpValidatorHook;
30+
31+
$alphanumericValidator = new RegexpValidatorHook('/^[A-Za-z0-9]+$/');
32+
$hexadecimalValidator = new RegexpValidatorHook('/^[0-9a-f]+$/');
33+
$asciiValidator = new RegexpValidatorHook('/^[ -~]$/');
34+
35+
// hooks can be applied to the global API, clients, providers, and resolution invocations
36+
37+
// all feature flag resolutions will use this validator
38+
$api = OpenFeatureAPI::getInstance();
39+
$api->addHooks($asciiValidator);
40+
41+
// invocations from this client will use this validator also
42+
$client = $api->getClient('example');
43+
$client->setHooks([$alphanumericValidator]);
44+
45+
// this specific invocation will use this validator also
46+
$client->resolveBooleanValue('test-flag', 'deadbeef', null, new EvaluationOptions([$hexadecimalValidator]));
47+
```
48+
49+
For more examples, see the [examples](./examples/).
50+
51+
## Development
52+
53+
### PHP Versioning
54+
55+
This library targets PHP version 7.4 and newer. As long as you have any compatible version of PHP on your system you should be able to utilize the OpenFeature SDK.
56+
57+
This package also has a `.tool-versions` file for use with PHP version managers like `asdf`.
58+
59+
### Installation and Dependencies
60+
61+
Install dependencies with `composer install`. `composer install` will update the `composer.lock` with the most recent compatible versions.
62+
63+
We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.
64+
65+
### Testing
66+
67+
Run tests with `composer run test`.

hooks/Validators/composer.json

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"name": "open-feature/validators-hook",
3+
"description": "A validator hooks package for OpenFeature",
4+
"license": "Apache-2.0",
5+
"type": "library",
6+
"keywords": [
7+
"featureflags",
8+
"featureflagging",
9+
"openfeature",
10+
"validator",
11+
"hook"
12+
],
13+
"authors": [
14+
{
15+
"name": "OpenFeature PHP Maintainers",
16+
"homepage": "https://github.com/orgs/open-feature/teams/php-maintainer"
17+
},
18+
{
19+
"name": "open-feature/php-sdk-contrib Contributors",
20+
"homepage": "https://github.com/open-feature/php-sdk-contrib/graphs/contributors"
21+
}
22+
],
23+
"require": {
24+
"php": "^7.4 || ^8",
25+
"open-feature/sdk": "^1.2.0"
26+
},
27+
"require-dev": {
28+
"ergebnis/composer-normalize": "^2.25",
29+
"friendsofphp/php-cs-fixer": "^3.13",
30+
"hamcrest/hamcrest-php": "^2.0",
31+
"mdwheele/zalgo": "^0.3.1",
32+
"mikey179/vfsstream": "v1.6.11",
33+
"mockery/mockery": "^1.5",
34+
"phan/phan": "^5.4",
35+
"php-parallel-lint/php-console-highlighter": "^1.0",
36+
"php-parallel-lint/php-parallel-lint": "^1.3",
37+
"phpstan/extension-installer": "^1.1",
38+
"phpstan/phpstan": "~1.9.0",
39+
"phpstan/phpstan-mockery": "^1.0",
40+
"phpstan/phpstan-phpunit": "^1.1",
41+
"psalm/plugin-mockery": "^0.9.1",
42+
"psalm/plugin-phpunit": "^0.18.0",
43+
"ramsey/coding-standard": "^2.0.3",
44+
"ramsey/composer-repl": "^1.4",
45+
"ramsey/conventional-commits": "^1.3",
46+
"roave/security-advisories": "dev-latest",
47+
"spatie/phpunit-snapshot-assertions": "^4.2",
48+
"vimeo/psalm": "~4.30.0"
49+
},
50+
"minimum-stability": "dev",
51+
"prefer-stable": true,
52+
"autoload": {
53+
"psr-4": {
54+
"OpenFeature\\Hooks\\Validators\\": "src"
55+
}
56+
},
57+
"autoload-dev": {
58+
"psr-4": {
59+
"OpenFeature\\Hooks\\Validators\\Test\\": "tests"
60+
}
61+
},
62+
"config": {
63+
"allow-plugins": {
64+
"phpstan/extension-installer": true,
65+
"dealerdirect/phpcodesniffer-composer-installer": true,
66+
"ergebnis/composer-normalize": true,
67+
"captainhook/plugin-composer": true,
68+
"ramsey/composer-repl": true
69+
},
70+
"sort-packages": true
71+
},
72+
"extra": {
73+
"captainhook": {
74+
"force-install": false
75+
}
76+
},
77+
"scripts": {
78+
"dev:analyze": [
79+
"@dev:analyze:phpstan",
80+
"@dev:analyze:psalm"
81+
],
82+
"dev:analyze:phpstan": "phpstan analyse --ansi --debug --memory-limit=512M",
83+
"dev:analyze:psalm": "psalm",
84+
"dev:build:clean": "git clean -fX build/",
85+
"dev:lint": [
86+
"@dev:lint:syntax",
87+
"@dev:lint:style"
88+
],
89+
"dev:lint:fix": "phpcbf",
90+
"dev:lint:style": "phpcs --colors",
91+
"dev:lint:syntax": "parallel-lint --colors src/ tests/",
92+
"dev:test": [
93+
"@dev:lint",
94+
"@dev:analyze",
95+
"@dev:test:unit",
96+
"@dev:test:integration"
97+
],
98+
"dev:test:coverage:ci": "phpunit --colors=always --coverage-text --coverage-clover build/coverage/clover.xml --coverage-cobertura build/coverage/cobertura.xml --coverage-crap4j build/coverage/crap4j.xml --coverage-xml build/coverage/coverage-xml --log-junit build/junit.xml",
99+
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/",
100+
"dev:test:unit": [
101+
"@dev:test:unit:setup",
102+
"phpunit --colors=always --testdox --testsuite=unit",
103+
"@dev:test:unit:teardown"
104+
],
105+
"dev:test:unit:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
106+
"dev:test:unit:setup": "echo 'Setup for unit tests...'",
107+
"dev:test:unit:teardown": "echo 'Tore down for unit tests...'",
108+
"dev:test:integration": [
109+
"@dev:test:integration:setup",
110+
"phpunit --colors=always --testdox --testsuite=integration",
111+
"@dev:test:integration:teardown"
112+
],
113+
"dev:test:integration:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
114+
"dev:test:integration:setup": "echo 'Setup for integration tests...'",
115+
"dev:test:integration:teardown": "echo 'Tore down integration tests...'",
116+
"test": "@dev:test"
117+
},
118+
"scripts-descriptions": {
119+
"dev:analyze": "Runs all static analysis checks.",
120+
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.",
121+
"dev:analyze:psalm": "Runs the Psalm static analyzer.",
122+
"dev:build:clean": "Cleans the build/ directory.",
123+
"dev:lint": "Runs all linting checks.",
124+
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.",
125+
"dev:lint:style": "Checks for coding standards issues.",
126+
"dev:lint:syntax": "Checks for syntax errors.",
127+
"dev:test": "Runs linting, static analysis, and unit tests.",
128+
"dev:test:coverage:ci": "Runs unit tests and generates CI coverage reports.",
129+
"dev:test:coverage:html": "Runs unit tests and generates HTML coverage report.",
130+
"dev:test:unit": "Runs unit tests.",
131+
"test": "Runs linting, static analysis, and unit tests."
132+
}
133+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*/vendor
2+
/*/composer.lock
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# OpenFeature Validators Hook example
2+
3+
This example provides an example of using the validators hooks for OpenFeature.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "open-feature/validators-hook-example",
3+
"description": "An example of using the validator hooks for OpenFeature",
4+
"type": "project",
5+
"license": "Apache-2.0",
6+
"authors": [
7+
{
8+
"name": "Tom Carrio",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"open-feature/sdk": "^1.2.0",
14+
"open-feature/validators-hook": "dev-main"
15+
},
16+
"repositories": [
17+
{
18+
"type": "path",
19+
"url": "../../",
20+
"options": {
21+
"versions": {
22+
"open-feature/validators-hook": "dev-main"
23+
}
24+
}
25+
}
26+
]
27+
}

0 commit comments

Comments
 (0)