承接 camoo/config-interop 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

camoo/config-interop

Composer 安装命令:

composer require camoo/config-interop

包简介

Common interface for immutable configuration access and interoperability.

README 文档

README

⚠️ Draft Proposal — This is a pre-submission draft for the PHP-FIG PSR process. The interfaces and specification are subject to change.

PHP 8.2+ License: MIT

What Is This?

This repository houses a PHP-FIG draft proposal for a minimal, immutable, framework-agnostic configuration interface: Config Proposal.

The goal is to let libraries, packages, and frameworks accept configuration through a single shared interface — without coupling either side to a specific framework or implementation.

The Problem

Every major PHP framework ships its own configuration container:

Framework Class Mutable? Framework-coupled?
Symfony ParameterBag
Laravel Illuminate\Config\Repository
Laminas Laminas\Config\Config Optional Partially
Nette ArrayHash Partially

A library author who needs to read a database.host value must today either:

  • Accept a raw array (no type safety, no IDE support, no contract),
  • Couple to a specific framework's container, or
  • Invent their own interface (fragmentation).

This proposal solves this by defining the smallest possible read-only interface that every framework can implement without sacrificing its own model.

The Interfaces

namespace ConfigInterop;

interface ConfigInterface
{
    /** Implementations MUST return false when the stored value is null. */
    public function has(string $key): bool;
    public function get(string $key, mixed $default = null): mixed;

    /** @return array<string, mixed> */
    public function all(): array;

    public function withPrefix(string $prefix): static;
}

interface ConfigProviderInterface
{
    public function getConfig(): ConfigInterface;
}

That's it. Four methods, zero runtime dependencies, PHP 8.2+.

has() checks key existence, even when the stored value is null.

Key Design Principles

Principle What it means
Immutable No set(), merge(), or push() — the interface is read-only
Framework-neutral Zero dependencies; works in any PHP project
Static-analysis-friendly PHPDoc on every member; static return preserves concrete types
Minimal surface Four methods cover all practical read use-cases
Prefix scoping withPrefix('db') scopes keys: get('host')db.host

Repository Layout

psr-config/
├── src/
│   ├── ConfigInterface.php           # Primary read interface
│   └── ConfigProviderInterface.php   # Factory / provider interface
├── docs/
│   └── config-interop-draft.md       # Full PSR draft document
├── examples/
│   ├── ArrayConfig.php               # Array-backed reference implementation
│   ├── EnvConfig.php                 # Environment-variable-backed implementation
│   ├── CachedConfigDecorator.php     # Caching decorator
│   ├── PrefixedConfig.php            # withPrefix() delegation example
│   └── LazyConfigProvider.php        # Deferred-instantiation provider
├── tests/
│   └── ConfigInterfaceComplianceTest.php
├── composer.json
├── CONTRIBUTING.md
└── LICENSE

Quick Start

composer require camoo/config-interop

Array-backed config

use ConfigInterop\Example\ArrayConfig;

$config = new ArrayConfig([
    'database' => [
        'host' => 'localhost',
        'port' => 5432,
    ],
    'cache' => [
        'enabled' => true,
        'ttl' => 3600,
    ],
]);

$config->get('database.host');          // 'localhost'
$config->has('database.port');          // true

$db = $config->withPrefix('database');
$db->get('host');                       // 'localhost'
$db->get('missing', 'default');         // 'default'

Env-backed config

use ConfigInterop\Example\EnvConfig;

// Reads APP_DATABASE_HOST, APP_DATABASE_PORT, etc.
$config = new EnvConfig(envPrefix: 'APP_');
$config->get('database.host');

Caching decorator

use ConfigInterop\Example\CachedConfigDecorator;

$config = new CachedConfigDecorator($expensiveConfig);
// Each key resolved at most once per instance lifetime.

Lazy provider

use ConfigInterop\Example\LazyConfigProvider;
use ConfigInterop\Example\ArrayConfig;

$provider = new LazyConfigProvider(
    static fn () => new ArrayConfig(require 'config.php')
);

// Config file is not loaded until this call:
$config = $provider->getConfig();

Library Authors — How to Accept Config

Accept ConfigInterface directly — do not depend on specific implementations:

use ConfigInterop\ConfigInterface;

class DatabaseConnection
{
    public function __construct(private readonly ConfigInterface $config) {}

    public function connect(): \PDO
    {
        $db = $this->config->withPrefix('database');

        return new \PDO(
            dsn:      sprintf('pgsql:host=%s;dbname=%s', $db->get('host'), $db->get('name')),
            username: $db->get('user'),
            password: $db->get('password'),
        );
    }
}

Running Tests & Static Analysis

composer install
composer test       # PHPUnit 11
composer analyse    # PHPStan level 9
composer check      # both

The Full PSR Proposal

See docs/config-interop-draft.md for the complete specification, including:

  • Behavioral requirements (MUST / SHOULD / MAY)
  • Immutability guarantees
  • Prefix scoping semantics
  • Error handling recommendations
  • Security & performance considerations
  • Prior art & ecosystem comparison
  • FAQ

Contributing

Please read CONTRIBUTING.md before opening a pull request or issue.

License

MIT © Camoo SARL. See LICENSE for details.

camoo/config-interop 适用场景与选型建议

camoo/config-interop 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「configuration」 「config」 「psr」 「immutable」 「interoperability」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 camoo/config-interop 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 camoo/config-interop 我们能提供哪些服务?
定制开发 / 二次开发

基于 camoo/config-interop 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-11