Skip to content

Commit

Permalink
feat: provide a base AbstractProvider for provider implementations to…
Browse files Browse the repository at this point in the history
… use
  • Loading branch information
tcarrio committed Oct 30, 2022
1 parent 2344c4a commit 78be67c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 29 deletions.
57 changes: 57 additions & 0 deletions src/implementation/provider/AbstractProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace OpenFeature\implementation\provider;

use OpenFeature\implementation\common\Metadata;
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
use OpenFeature\interfaces\flags\EvaluationContext;
use OpenFeature\interfaces\hooks\Hook;
use OpenFeature\interfaces\provider\Provider;
use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface;
use Psr\Log\LoggerAwareTrait;

abstract class AbstractProvider implements Provider
{
use LoggerAwareTrait;

protected static string $NAME = 'AbstractProvider';

/** @var Hook[] $hooks */
private array $hooks = [];

public function getMetadata(): MetadataInterface
{
return new Metadata(self::$NAME);
}

abstract public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;

abstract public function resolveStringValue(string $flagKey, string $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;

abstract public function resolveIntegerValue(string $flagKey, int $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;

abstract public function resolveFloatValue(string $flagKey, float $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;

/**
* @inheritdoc
*/
abstract public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;

/**
* @return Hook[]
*/
public function getHooks(): array
{
return $this->hooks;
}

/**
* @param Hook[] $hooks
*/
public function setHooks(array $hooks): void
{
$this->hooks = $hooks;
}
}
31 changes: 2 additions & 29 deletions src/implementation/provider/NoOpProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@

namespace OpenFeature\implementation\provider;

use OpenFeature\implementation\common\Metadata;
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
use OpenFeature\interfaces\flags\EvaluationContext;
use OpenFeature\interfaces\hooks\Hook;
use OpenFeature\interfaces\provider\Provider;
use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface;
use Psr\Log\LoggerAwareTrait;

class NoOpProvider implements Provider
class NoOpProvider extends AbstractProvider implements Provider
{
use LoggerAwareTrait;

private static string $NAME = 'NoOpProvider';

public function getMetadata(): MetadataInterface
{
return new Metadata(self::$NAME);
}
protected static string $NAME = 'NoOpProvider';

public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface
{
Expand Down Expand Up @@ -50,20 +39,4 @@ public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationCo
{
return ResolutionDetailsFactory::fromSuccess($defaultValue);
}

/**
* @return Hook[]
*/
public function getHooks(): array
{
return [];
}

/**
* @param Hook[] $hooks
*/
public function setHooks(array $hooks): void
{
// no-op
}
}

0 comments on commit 78be67c

Please sign in to comment.