PHPackages                             hershel-theodore-layton/printf-state-machine - 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. hershel-theodore-layton/printf-state-machine

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

hershel-theodore-layton/printf-state-machine
============================================

Generate HH\\FormatString&lt;T&gt; state machines

v0.2.2(2mo ago)0304↓33.3%1MITHackCI passing

Since Jul 5Pushed 2mo agoCompare

[ Source](https://github.com/hershel-theodore-layton/printf-state-machine)[ Packagist](https://packagist.org/packages/hershel-theodore-layton/printf-state-machine)[ RSS](/packages/hershel-theodore-layton-printf-state-machine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (1)

Printf State Machine
====================

[](#printf-state-machine)

*Generate HH\\FormatString&lt;T&gt; state machines.*

This package uses a code generator to create state machines that process `HH\FormatString` with their arguments and the accompanying typesafety interfaces. This is a `--dev` dependency. You don't need this generator in production to use the state machines.

Usage
-----

[](#usage)

You can chain together your own format string DSL in little to no time. Start with `PrintfStateMachine\Factory::create()` and chain `->with...` methods. Once your DSL is ready, invoke `|> PrintfStateMachine\codegen($$, PrintfStateMachine\ENGINE_TEMPLATE)`. You will get `Entities`, which are "just code". Put this code somewhere in a namespace it won't conflict with any other engines. Then create a typesafe caller.

```
function your_format_function(
  \HH\FormatString $format,
  mixed ... $args
)[]: (string, vec) {
  return \YourNamespace\engine($format, $args);
}
```

This will transform your format and arguments according to the rules you've set out in your factory.

Use case
--------

[](#use-case)

`HH\Lib\SQL\Query` has support for these specifiers:

SpecifierEffect`%d  %f  %s`nullable int, float, and string`%=d %=f %=s`equality for int, float, and string`%C  %T`column and table names`%Ld %Lf %Ls %LC`list of int, float, string, and column`%K``/* comments */``%Q`nested Query objectsYou may very well want to add a strongly typed `%N` for `TableAndColumnName`to make sure that you never accidentally switch around a column name and a user supplied value. Short of patching the Hack typechecker, or building a very difficult to write linter that depends on type information, you'd need a tool like this. Write a definition for 12 (excluding `%C` and `%T`) specifiers and add `->withRewrite('N', 'C')`. The format and args were typechecked by Hack.

A library will be published with these implementations.

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance91

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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 ~77 days

Total

4

Last Release

73d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d16d159b7061287c506d4ab44d05ae042bc4ec697116d1bd132a007634d9ff21?d=identicon)[Hershel Theodore Layton](/maintainers/Hershel%20Theodore%20Layton)

---

Top Contributors

[![hershel-theodore-layton](https://avatars.githubusercontent.com/u/81193606?v=4)](https://github.com/hershel-theodore-layton "hershel-theodore-layton (23 commits)")

### Embed Badge

![Health badge](/badges/hershel-theodore-layton-printf-state-machine/health.svg)

```
[![Health](https://phpackages.com/badges/hershel-theodore-layton-printf-state-machine/health.svg)](https://phpackages.com/packages/hershel-theodore-layton-printf-state-machine)
```

###  Alternatives

[hhvm/hsl

The Hack Standard Library

1151.1M55](/packages/hhvm-hsl)

PHPackages © 2026

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