Skip to content

Commit 6ffffe9

Browse files
committed
feat: provide a base AbstractProvider for provider implementations to use
Signed-off-by: Tom Carrio <[email protected]>
1 parent 2344c4a commit 6ffffe9

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenFeature\implementation\provider;
6+
7+
use OpenFeature\implementation\common\Metadata;
8+
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
9+
use OpenFeature\interfaces\flags\EvaluationContext;
10+
use OpenFeature\interfaces\hooks\Hook;
11+
use OpenFeature\interfaces\provider\Provider;
12+
use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface;
13+
use Psr\Log\LoggerAwareTrait;
14+
15+
abstract class AbstractProvider implements Provider
16+
{
17+
use LoggerAwareTrait;
18+
19+
protected static string $NAME = 'AbstractProvider';
20+
21+
/** @var Hook[] $hooks */
22+
private array $hooks = [];
23+
24+
public function getMetadata(): MetadataInterface
25+
{
26+
return new Metadata(self::$NAME);
27+
}
28+
29+
abstract public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;
30+
31+
abstract public function resolveStringValue(string $flagKey, string $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;
32+
33+
abstract public function resolveIntegerValue(string $flagKey, int $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;
34+
35+
abstract public function resolveFloatValue(string $flagKey, float $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
abstract public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;
41+
42+
/**
43+
* @return Hook[]
44+
*/
45+
public function getHooks(): array
46+
{
47+
return $this->hooks;
48+
}
49+
50+
/**
51+
* @param Hook[] $hooks
52+
*/
53+
public function setHooks(array $hooks): void
54+
{
55+
$this->hooks = $hooks;
56+
}
57+
}

src/implementation/provider/NoOpProvider.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@
44

55
namespace OpenFeature\implementation\provider;
66

7-
use OpenFeature\implementation\common\Metadata;
8-
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
97
use OpenFeature\interfaces\flags\EvaluationContext;
10-
use OpenFeature\interfaces\hooks\Hook;
118
use OpenFeature\interfaces\provider\Provider;
129
use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface;
13-
use Psr\Log\LoggerAwareTrait;
1410

15-
class NoOpProvider implements Provider
11+
class NoOpProvider extends AbstractProvider implements Provider
1612
{
17-
use LoggerAwareTrait;
18-
19-
private static string $NAME = 'NoOpProvider';
20-
21-
public function getMetadata(): MetadataInterface
22-
{
23-
return new Metadata(self::$NAME);
24-
}
13+
protected static string $NAME = 'NoOpProvider';
2514

2615
public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface
2716
{
@@ -50,20 +39,4 @@ public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationCo
5039
{
5140
return ResolutionDetailsFactory::fromSuccess($defaultValue);
5241
}
53-
54-
/**
55-
* @return Hook[]
56-
*/
57-
public function getHooks(): array
58-
{
59-
return [];
60-
}
61-
62-
/**
63-
* @param Hook[] $hooks
64-
*/
65-
public function setHooks(array $hooks): void
66-
{
67-
// no-op
68-
}
6942
}

0 commit comments

Comments
 (0)