定制 0xc/openfeature 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

0xc/openfeature

Composer 安装命令:

composer require 0xc/openfeature

包简介

PHP implementation of the OpenFeature SDK

README 文档

README

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Specification Latest Stable Version Total Downloads License

Alpha Checklist

  • spec compliant
  • contains test suite which verifies behavior consistent with spec
  • contains test suite with reasonable coverage
  • automated publishing
  • comprehensive readme

Disclaimer

I'm throwing this project together as a potential demo-phase of OpenFeature for PHP, with future work surrounding a Split PHP provider (probably utilizing their existing package). It is not complete and is very much work in progress.

Overview

This package provides a functional SDK for an OpenFeature API and client. It 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).

Future development may aim to allow this library to be auto-loaded by filepath (PSR-4) and optionally integrate with the container standards (PSR-11) over global $_SESSION access.

Installation

$ composer require 0xc/openfeature   // installs the latest version

Usage

While Boolean provides the simplest introduction, we offer a variety of flag types.

use OpenFeature\OpenFeatureClient;

class MyClass {
  private OpenFeatureClient $client;

  public function __construct() {
    $this->client = OpenFeatureAPI->getInstance()->getClient('MyClass');
  }

  public function booleanExample(): UI
  {
      // Should we render the redesign? Or the default webpage? 
      if ($this->client->getBooleanValue('redesign_enabled', false)) {
          return render_redesign();
      }
      return render_normal();
  }

  public function stringExample(): Template
  {
      // Get the template to load for the custom new homepage
      $template = $this->client->getStringValue('homepage_template', 'default-homepage.html');

      return render_template($template);
  }

  public function numberExample(): List<HomepageModule>
  {
      // How many modules should we be fetching?
      $count = $this->client->getIntegerValue('module-fetch-count', 4);

      return fetch_modules($count);
  }

  public function structureExample(): HomepageModule
  {
      $obj = $this->client->getObjectValue('hero-module', $previouslyDefinedDefaultStructure);

      return HomepageModuleBuilder::new()
              ->title($obj->getValue('title'))
              ->body($obj->getValue('description'))
              ->build();
  }
}

Configuration

To configure OpenFeature, you'll need to add a provider to the global singleton OpenFeatureAPI. From there, you can generate a Client which is usable by your code. If you do not set a provider, then the NoOpProvider, which simply returns the default passed in, will be used.

use OpenFeature\OpenFeatureAPI;
use OpenFeature\Providers\Flagd\FlagdProvider;

class MyApp {
    public function bootstrap(){
        $api = OpenFeatureAPI.getInstance();
        $api->setProvider(new FlagdProvider());
        $client = $api->getClient();

        // Now use your `$client` instance to evaluate some feature flags!
    }
}

Development

PHP Versioning

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.

This package also has a .tool-versions file for use with PHP version managers like asdf.

Installation and Dependencies

Install dependencies with composer install. composer install will update the composer.lock with the most recent compatible versions.

We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.

Testing

Run tests with composer run test.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-09-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固