flyokai/generic 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

flyokai/generic

Composer 安装命令:

composer require flyokai/generic

包简介

Generics definitions

README 文档

README

User docs → README.md · Agent quick-ref → CLAUDE.md · Agent deep dive → AGENTS.md

Builder, tuner, and execution-pipeline patterns expressed with PHPDoc generics — a tiny but pervasive primitive across Flyokai.

The package gives you four parametric interfaces — State<T>, Builder<T>, Tuner<T>, Execution<T> — plus DI-aware containers that compose them. Tuners are how Flyokai lets multiple modules contribute settings to one shared object (an InputDefinition, a Router, an ACL builder, …) without coupling them.

Features

  • State<T> / Builder<T> — generic state holder + builder pipeline
  • Tuner<T> / TunerContainer<T> — composable, ordered state mutators
  • Execution<TContext> / ExecutionContainer<TContext> — composable side-effect runners
  • InvalidStateException — base for builder validation errors
  • Fully PHPDoc-@template annotated for static analysers

Installation

composer require flyokai/generic

Quick start

use Flyokai\Generic\State;
use Flyokai\Generic\BuilderImpl;
use Flyokai\Generic\Tuner;

/** @implements State<\stdClass> */
final class ObjectState implements State
{
    public function __construct(public \stdClass $value) {}
    public function get(): \stdClass { return $this->value; }
}

/** @implements Tuner<\stdClass> */
final class GreetingTuner implements Tuner
{
    public function tune(State $state): State
    {
        $state->value->greeting = 'hello';
        return $state;
    }
}

/** @extends BuilderImpl<\stdClass> */
final class ObjectBuilder extends BuilderImpl {}

$builder = new ObjectBuilder(
    fn() => new ObjectState(new \stdClass()),
    new GreetingTuner(),
);

$obj = $builder->build();   // \stdClass { greeting: "hello" }

Composing tuners

use Flyokai\Generic\TunerContainer;
use Amp\Injector\Composition;

$tuners = new TunerContainer($composition);  // Composition from amphp-injector
$state  = $tuners->tune($state);             // applies every tuner in order

TunerContainer accepts an Amp\Injector\Composition of Tuner<T> instances — each module registers its own tuner via DI and ordering (before/after/depends) decides who runs when.

Executions

Execution<TContext> is the side-effect cousin of Tuner — it runs against a context but does not return modified state:

use Flyokai\Generic\Execution;
use Flyokai\Generic\ExecutionContainer;

/** @implements Execution<MyCtx> */
final class LogExecution implements Execution
{
    public function execute(mixed $context): void
    {
        $context->logger->info('done');
    }
}

$pipeline = new ExecutionContainer($composition);
$pipeline->execute($context);

Subclassing ExecutionContainer and overriding executeChild() lets you inject hooks (timing, error handling) around every child execution.

Where it shows up

  • flyokai/symfony-consoleInputState is State<InputInterface>; RequiredOptionHandler and friends are tuners.
  • flyokai/application — ACL Builder, RouterBuilder, ServerBuilder all expose tuner compositions so modules can extend them.
  • flyokai/data-service, flyokai/oauth-serverRouterBuilder middleware and route registration.

Gotchas

  • BuilderImpl is abstract; you must subclass to constrain the generic parameter.
  • Tuner order in a TunerContainer is significant — wire ordering carefully via compositionItem(...) before/after/depends.
  • ExecutionContainer does not aggregate return values — they are intentionally void.
  • PHPDoc @template annotations are static-analysis only; nothing enforces the type at runtime.

See also

  • flyokai/amphp-injector — provides the Composition mechanism TunerContainer and ExecutionContainer rely on.

License

MIT

flyokai/generic 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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