flyokai/misc
Composer 安装命令:
composer require flyokai/misc
包简介
Various helpers
README 文档
README
User docs →
README.md· Agent quick-ref →CLAUDE.md· Agent deep dive →AGENTS.md
A grab-bag of small utilities that don't deserve their own packages: cryptographic key handling, profiling, PSR-7 ↔ AMPHP bridging, and async sequencing.
These helpers exist because they're shared between two or more flyokai packages and are too small to release individually.
Features
CryptKey— secure OpenSSL key holder (RSA, EC) with file-permission validation, derived fromleague/oauth2-serverProfilerFacade/ProfilerStat— Magento-style nested profiler with memory trackingPsrServerAdapter— bidirectional AMPHP HTTP ↔ PSR-7 converterSharedSequence— monotonic position-based fiber synchronisation primitive
Installation
composer require flyokai/misc
CryptKey
use Flyokai\Misc\CryptKey; $key = new CryptKey('/path/to/private.pem', passPhrase: null, keyPermissionsCheck: true); $key->getKeyContents(); // PEM contents (string) $key->getKeyPath(); $key->getPassPhrase();
- Accepts a path with or without
file://prefix, or raw PEM material - Validates RSA / EC types via OpenSSL on construction
- Refuses files whose mode isn't one of
400,440,600,640,660(configurable via$keyPermissionsCheck)
ProfilerFacade
A static profiling facade with nested timers and memory metrics:
use Flyokai\Misc\ProfilerFacade; ProfilerFacade::setEnabled(true); ProfilerFacade::start('request'); ProfilerFacade::start('request->db->query'); // … work … ProfilerFacade::stop('request->db->query'); ProfilerFacade::stop('request'); foreach (ProfilerFacade::getAllStat() as $line) { echo $line, "\n"; // request: 12.34 ms, count=1, avg=12.34 ms, real=512 KB, emalloc=200 KB }
When disabled (the production default), every call is a silent no-op. Hierarchy is expressed through -> separators in timer IDs.
ProfilerStat::getFilteredTimerIds($thresholds, $filterRegex) returns timers above given thresholds, optionally filtered by regex.
PsrServerAdapter
Used by the OAuth server to bridge League OAuth2 (PSR-7) with the AMPHP HTTP server:
use Flyokai\Misc\PsrServerAdapter; $adapter = new PsrServerAdapter(); $psrRequest = $adapter->toPsrServerRequest($ampRequest); $ampResponse = $adapter->fromPsrServerResponse($psrResponse, $ampRequest);
| Method | Direction |
|---|---|
toPsrServerRequest(Request) |
AMPHP → PSR-7 |
fromPsrServerRequest(PsrServerRequest, Client) |
PSR-7 → AMPHP |
toPsrServerResponse(Response) |
AMPHP → PSR-7 |
fromPsrServerResponse(PsrResponse, Request) |
PSR-7 → AMPHP |
Headers, cookies, query params, attributes and the body are mapped. Pass withBody: false to drop the body.
SharedSequence
A coroutine-ordering primitive — fibers wait until a monotonic position is reached:
use Flyokai\Misc\SharedSequence; $seq = new SharedSequence(); // Fiber A $seq->await(5); // suspends until position >= 5 // Fiber B $seq->resume(5); // advances to position 6, resumes any waiters whose target is <= 5
await(int $position): void— suspends the current fiber until$positionis reachedresume(int $position): void— sets position tomax($position, $current) + 1and resumes all matching waiters
Position only ever moves forward — once advanced past a value, you can't await it again.
Gotchas
CryptKeymay try to read your raw key as a path — if the literal happens to be a valid file path, OpenSSL will load that file instead. Inspect input.ProfilerFacadeis silent when disabled —getAllStat()returns an empty array. There's no warning that profiling is off.PsrServerAdapterbuffers the body intoPsrServerRequest()— inefficient for very large requests.SharedSequenceis strictly monotonic — once advanced, earlier positions can't be awaited.
See also
flyokai/oauth-serverusesCryptKeyandPsrServerAdapter.flyokai/symfony-consoleships aCryptKeyValidatorbuilt onCryptKey.
License
MIT
flyokai/misc 适用场景与选型建议
flyokai/misc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 flyokai/misc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flyokai/misc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-24