承接 flexi/contracts 相关项目开发

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

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

flexi/contracts

Composer 安装命令:

composer require flexi/contracts

包简介

Contracts and PSR dependencies for Flexi Framework - Central interface package

README 文档

README

License: MIT PHP Version PSR Compatible

Contracts and PSR dependencies for Flexi Framework - Central interface package that ensures a single point of dependency between different pieces of the Flexi Framework ecosystem.

Purpose

flexi/contracts exists to guarantee a unique dependency point between the various components of the Flexi Framework (core and modules). This package serves as the foundation for maintaining loose coupling and high cohesion across the entire framework architecture.

Key Benefits

  • 🔗 Single Dependency Point: All framework components depend on contracts, not on concrete implementations
  • 📦 Modular Architecture: Modules can be developed independently while sharing common interfaces
  • 🎯 Loose Coupling: Core and modules communicate through well-defined contracts
  • ✅ PSR Standards Compliance: Full compatibility with PHP-FIG PSR standards
  • 🔄 Flexibility: Optional base classes and interfaces for common use cases

What's Included

This package includes:

  1. PSR Standards Dependencies - Complete PSR compatibility out of the box
  2. Framework Interfaces - Core contracts for the Flexi ecosystem
  3. Base Classes - Optional abstract classes for common patterns
  4. Value Objects - Reusable immutable value objects
  5. Utility Traits - Helper traits for common functionality

Installation

composer require flexi/contracts

Package Contents

📋 Interfaces (26 contracts)

The package provides interfaces for all major framework components:

CQRS Pattern

  • BusInterface - Command/Query bus abstraction
  • HandlerInterface - Handler for commands and queries
  • DTOInterface - Data Transfer Object contract
  • CliDTOInterface - CLI-specific DTO contract
  • MessageInterface - Message contract for responses

Event Management

  • EventBusInterface - Event dispatcher abstraction
  • EventInterface - Event contract
  • EventListenerInterface - Event listener contract

Data Access

  • RepositoryInterface - Generic repository pattern
  • CriteriaInterface - Query criteria pattern
  • EntityInterface - Domain entity contract
  • CollectionInterface - Collection contract

Persistence & Caching

  • CacheInterface - Cache abstraction (PSR-16 compatible)
  • SessionStorageInterface - Session storage contract
  • LogRepositoryInterface - Log persistence contract
  • LogInterface - Log entity contract

Configuration

  • ConfigurationInterface - Configuration access contract
  • ConfigurationRepositoryInterface - Configuration repository contract
  • SecretProviderInterface - Secret/credential provider contract

Dependency Injection

  • ObjectBuilderInterface - Object builder/factory contract
  • ServiceDefinitionInterface - Service definition contract
  • FactoryInterface - Generic factory contract

UI & Templates

  • TemplateEngineInterface - Template rendering engine
  • TemplateInterface - Template representation
  • TemplateLocatorInterface - Template discovery

Foundation

  • ValueObjectInterface - Value object contract

🏗️ Base Classes (8 implementations)

Optional abstract and concrete classes for common patterns:

  • Collection - Generic collection implementation
  • ObjectCollection - Type-safe object collection
  • EventListener - Abstract event listener base
  • HttpHandler - Abstract HTTP request handler (PSR-15)
  • Log - Log entity implementation
  • PlainTextMessage - Simple message implementation
  • PsrLogger - PSR-3 logger adapter

Criteria Pattern

  • AnyCriteria - Null object pattern for criteria

💎 Value Objects (6 immutables)

Domain-driven value objects:

  • ID - Unique identifier
  • Version - Semantic version representation
  • LogLevel - PSR-3 log levels
  • CollectionType - Collection type descriptor
  • Order - Sort order (ASC/DESC)
  • Operator - Comparison operators

🛠️ Utility Traits (6 helpers)

Reusable functionality:

  • CacheKeyGeneratorTrait - Cache key generation
  • FileHandlerTrait - File system operations
  • GlobFileReader - Glob pattern file reading
  • JsonFileReader - JSON file parsing
  • InstalledModulesProviderTrait - Module discovery
  • OSDetectorTrait - Operating system detection

PSR Standards Included

This package includes and enforces compatibility with:

  • PSR-1: Basic Coding Standard
  • PSR-3: Logger Interface (via psr/log)
  • PSR-6: Caching Interface (via psr/cache)
  • PSR-7: HTTP Message Interface (via psr/http-message)
  • PSR-11: Container Interface (via psr/container)
  • PSR-14: Event Dispatcher (via psr/event-dispatcher)
  • PSR-15: HTTP Server Request Handlers (via psr/http-server-handler & psr/http-server-middleware)
  • PSR-16: Simple Cache (via psr/simple-cache)
  • PSR-17: HTTP Factories (via psr/http-factory)
  • PSR-18: HTTP Client (via psr/http-client)
  • PSR-20: Clock (via psr/clock)

Usage Philosophy

For Framework Core

The core should:

  • ✅ Depend on contracts from this package
  • ✅ Implement interfaces defined here
  • ❌ Never create its own interfaces that modules need
  • ❌ Never depend on module implementations

For Modules

Modules should:

  • ✅ Depend on contracts from this package
  • ✅ Implement interfaces defined here
  • ✅ Use optional base classes if needed
  • ✅ Declare explicit dependency on other modules in composer.json to resolve automatically and avoid incompatibilities
  • ❌ Never depend on the core directly

Optional Usage

All base classes, value objects, and traits are optional. You can:

  • Use only the interfaces you need
  • Implement your own base classes
  • Create custom value objects
  • Skip utility traits if not needed

Example: Using Contracts

use Flexi\Contracts\Interfaces\HandlerInterface;
use Flexi\Contracts\Interfaces\DTOInterface;
use Flexi\Contracts\Interfaces\MessageInterface;
use Flexi\Contracts\Classes\PlainTextMessage;

class MyCommandHandler implements HandlerInterface
{
    public function handle(DTOInterface $command): MessageInterface
    {
        // Your business logic here
        return new PlainTextMessage('Command executed successfully');
    }
}

Example: Using Value Objects

use Flexi\Contracts\ValueObjects\ID;
use Flexi\Contracts\ValueObjects\Version;

$userId = new ID('user-123');
$appVersion = new Version(1, 5, 0);

echo $appVersion; // "1.5.0"

Example: Using Base Classes

use Flexi\Contracts\Classes\EventListener;
use Flexi\Contracts\Interfaces\EventInterface;

class MyEventListener extends EventListener
{
    public function handleEvent(EventInterface $event): void
    {
        // React to the event
        $data = $event->getData();
        // Process...
    }
}

Requirements

  • PHP 7.4 or higher
  • Composer

License

MIT License - see LICENSE file for details.

Contributing

This package is part of the Flexi Framework ecosystem. Contributions are welcome following these guidelines:

  1. Interface Changes: Require careful consideration as they affect the entire ecosystem
  2. New Interfaces: Should solve common problems across multiple modules
  3. Base Classes: Should be optional and follow SOLID principles
  4. PSR Compliance: Must maintain compatibility with PSR standards

Versioning

This package follows Semantic Versioning:

  • MAJOR: Breaking changes to interfaces
  • MINOR: New interfaces or optional features
  • PATCH: Bug fixes and documentation

Links

Architecture

┌─────────────────────────────────────────┐
│         Flexi Framework Core            │
│     (Business Logic & Orchestration)    │
└─────────────┬───────────────────────────┘
              │ depends on
              ↓
┌─────────────────────────────────────────┐
│       flexi/contracts                   │
│  (Interfaces, Base Classes, PSR deps)   │
└─────────────┬───────────────────────────┘
              ↑ depends on
              │
┌─────────────┴───────────────────────────┐
│                                         │
│  ┌──────────────┐  ┌──────────────┐    │
│  │ Auth Module  │  │ Cache Module │    │
│  └──────────────┘  └──────────────┘    │
│  ┌──────────────┐  ┌──────────────┐    │
│  │  UI Module   │  │  Log Module  │    │
│  └──────────────┘  └──────────────┘    │
│         ... more modules ...            │
└─────────────────────────────────────────┘

Support

For questions and support:

Made with ❤️ for the Flexi Framework ecosystem

flexi/contracts 适用场景与选型建议

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

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

围绕 flexi/contracts 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-04