PHPackages                             flyokai/misc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. flyokai/misc

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

flyokai/misc
============

Various helpers

0.1.0(1mo ago)07↓100%1MITPHPPHP ^8.1

Since Apr 25Pushed 2w agoCompare

[ Source](https://github.com/flyokai/misc)[ Packagist](https://packagist.org/packages/flyokai/misc)[ RSS](/packages/flyokai-misc/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (8)Used By (1)

flyokai/misc
============

[](#flyokaimisc)

> User docs → [`README.md`](README.md) · Agent quick-ref → [`CLAUDE.md`](CLAUDE.md) · Agent deep dive → [`AGENTS.md`](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
--------

[](#features)

- **`CryptKey`** — secure OpenSSL key holder (RSA, EC) with file-permission validation, derived from `league/oauth2-server`
- **`ProfilerFacade` / `ProfilerStat`** — Magento-style nested profiler with memory tracking
- **`PsrServerAdapter`** — bidirectional AMPHP HTTP ↔ PSR-7 converter
- **`SharedSequence`** — monotonic position-based fiber synchronisation primitive

Installation
------------

[](#installation)

```
composer require flyokai/misc
```

CryptKey
--------

[](#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
--------------

[](#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
----------------

[](#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);
```

MethodDirection`toPsrServerRequest(Request)`AMPHP → PSR-7`fromPsrServerRequest(PsrServerRequest, Client)`PSR-7 → AMPHP`toPsrServerResponse(Response)`AMPHP → PSR-7`fromPsrServerResponse(PsrResponse, Request)`PSR-7 → AMPHPHeaders, cookies, query params, attributes and the body are mapped. Pass `withBody: false` to drop the body.

SharedSequence
--------------

[](#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
