PHPackages                             waffle-commons/utils - 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. waffle-commons/utils

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

waffle-commons/utils
====================

Utils component for Waffle framework.

0.1.0-beta4(2w ago)11.8k6MITPHPPHP ^8.5CI passing

Since Dec 10Pushed 1mo agoCompare

[ Source](https://github.com/waffle-commons/utils)[ Packagist](https://packagist.org/packages/waffle-commons/utils)[ RSS](/packages/waffle-commons-utils/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (36)Versions (27)Used By (6)

[![Discord](https://camo.githubusercontent.com/b30f41baece56d71f7f496f7e39fd33a2a096221c66c648b350dd4fe14276c2e/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3735353238383030313539323033333339313f6c6f676f3d646973636f7264)](https://discord.gg/eKgywnfXr2)[![PHP Version Require](https://camo.githubusercontent.com/083f8c21e5dcfa89ab647ef1fd3b8fccd368d7f40f3ad63efa9473ddd4602cab/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f7574696c732f726571756972652f706870)](https://packagist.org/packages/waffle-commons/utils)[![PHP CI](https://github.com/waffle-commons/utils/actions/workflows/main.yml/badge.svg)](https://github.com/waffle-commons/utils/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/f047ab231016897c821d76eb4d1a774f57515e16d35dd2f1faf79280870f21e5/68747470733a2f2f636f6465636f762e696f2f67682f776166666c652d636f6d6d6f6e732f7574696c732f67726170682f62616467652e7376673f746f6b656e3d64373461633632612d373837322d343033352d386238622d626363336166313939316530)](https://codecov.io/gh/waffle-commons/utils)[![Latest Stable Version](https://camo.githubusercontent.com/10ba41cc4b4cbdf61e23e60da762cc4b1ae6ccb24449a1f4064f31b6a7ce8f31/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f7574696c732f76)](https://packagist.org/packages/waffle-commons/utils)[![Latest Unstable Version](https://camo.githubusercontent.com/3fc86062bbbdac3835c22994c1ff1a82ba4f882c9c4e98d0b00f274a843fd033/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f7574696c732f762f756e737461626c65)](https://packagist.org/packages/waffle-commons/utils)[![Total Downloads](https://camo.githubusercontent.com/85bdb6136b8bffa7e849abdb70b756d49aba4f43c2a96d65a03dca1dcdee9f73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776166666c652d636f6d6d6f6e732f7574696c732e737667)](https://packagist.org/packages/waffle-commons/utils)[![Packagist License](https://camo.githubusercontent.com/d2a3b5a84f0042c447f08b6ef1c21f265198cdcee97fdf14a37f3383fa36144c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776166666c652d636f6d6d6f6e732f7574696c73)](https://github.com/waffle-commons/utils/blob/main/LICENSE.md)

Waffle Utils Component
======================

[](#waffle-utils-component)

> **Release:** `0.1.0-beta4` | [`CHANGELOG.md`](./CHANGELOG.md)

Stateless, pure-function helpers shared across the Waffle ecosystem. The package intentionally has no I/O dependencies and no per-process state — every helper here is safe to use across FrankenPHP worker requests without reset.

🆕 Beta-1 change
---------------

[](#-beta-1-change)

The former `Waffle\Commons\Utils\Trait\ReflectionTrait` has been **removed** and decomposed into three single-responsibility `final readonly` services (Beta-1 Phase 1 architectural pass — Single Responsibility over trait-based reuse). Consumers inject the service they need instead of mixing in a trait.

📦 Installation
--------------

[](#-installation)

```
composer require waffle-commons/utils
```

🧱 Surface
---------

[](#-surface)

ClassRole`Waffle\Commons\Utils\Service\ClassParser`Tokenizer-based class introspection. `className(string $path): string` reads a PHP file with `token_get_all()` (no regex, no eval) and returns the fully qualified class/interface/trait/enum name, or `''` if none. Used by routing's `RouteDiscoverer` / `ControllerFinder`.`Waffle\Commons\Utils\Service\AttributeReader``newAttributeInstance(object $target, string $attribute): object` resolves an attribute instance from a target, falling back to a zero-arg instance when the target carries no matching attribute (preserving the former trait's contract).`Waffle\Commons\Utils\Service\ReflectionInspector`Object-shape inspection: `isFinal()`, `isInstance()`, `getProperties()`, `getMethods()`.The package grows only when a helper is genuinely shared across more than one component.

🔍 `ClassParser`
---------------

[](#-classparser)

Reads a PHP file with `token_get_all()` (no regex, no eval) and returns the fully qualified class/interface/trait/enum name found inside, or an empty string if none is present.

```
use Waffle\Commons\Utils\Service\ClassParser;

$parser = new ClassParser();
$fqcn = $parser->className('/path/to/UserController.php'); // 'App\Controller\UserController'
```

The implementation handles:

- Bracketed (`namespace App { … }`) and statement (`namespace App;`) namespace forms.
- PHP 8.x `final`, `readonly`, `abstract` modifiers in front of `class`/`interface`/`trait`/`enum`.
- Anonymous classes — they are skipped (returns the first non-anonymous declaration).

🐘 PHP 8.5 surface
-----------------

[](#-php-85-surface)

All three services are `final readonly class` with strict types and explicit return types throughout. They hold no mutable state and are safe to reuse across FrankenPHP worker requests.

🧭 Architectural boundary (`mago guard`)
---------------------------------------

[](#-architectural-boundary-mago-guard)

An active dependency **perimeter** is enforced on every CI run by `vendor/bin/mago guard` (bundled into `composer mago`; zero baselines). The rules live in [`mago.toml`](./mago.toml) under `[guard.perimeter]` — a forbidden `use` statement fails the build, not a reviewer.

Production code under `Waffle\Commons\Utils` may depend **only** on:

- `Waffle\Commons\Utils\**` — itself
- `Waffle\Commons\Contracts\**` — the shared contracts package, the **only** Waffle dependency permitted
- `Psr\**` — PSR interfaces
- `@global` + `Psl\**` — PHP core and the PHP Standard Library

Test code under `WaffleTests\Commons\Utils` is unrestricted (`@all`). Structural rules are guarded too: interfaces must be named `*Interface`, `Exception\**` classes must end in `*Exception`, and any `Enum\**` namespace may hold only `enum` declarations.

Contract-first, component-agnostic by construction: components compose through `waffle-commons/contracts`, never directly through one another.

🧪 Testing
---------

[](#-testing)

```
docker exec -w /waffle-commons/utils waffle-dev composer tests
```

📄 License
---------

[](#-license)

MIT — see [LICENSE.md](./LICENSE.md).

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance94

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~5 days

Total

10

Last Release

20d ago

PHP version history (2 changes)0.1.0-alpha3PHP ^8.4

0.1.0-alpha4PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/34a7557a3fb23aaf788ca3892b9b7efdf96e753264bafd0599153c9e8a921316?d=identicon)[LesliePetrimaux](/maintainers/LesliePetrimaux)

---

Top Contributors

[![supa-chayajin](https://avatars.githubusercontent.com/u/695448?v=4)](https://github.com/supa-chayajin "supa-chayajin (46 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/waffle-commons-utils/health.svg)

```
[![Health](https://phpackages.com/badges/waffle-commons-utils/health.svg)](https://phpackages.com/packages/waffle-commons-utils)
```

###  Alternatives

[cmgmyr/messenger

Simple user messaging tool for Laravel

2.6k2.5M6](/packages/cmgmyr-messenger)[mtymek/blast-reflection-factory

Universal auto-wiring factory for Laminas ServiceManager.

1967.4k](/packages/mtymek-blast-reflection-factory)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
