npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polyprism/php-shared

v0.3.1

Published

Shared PHP rendering primitives used by PolyPrism's Prisma 6 & 7 PHP generators (php-class, php-readonly, php-domain-class). Pure ESM.

Readme

@polyprism/php-shared

PHP rendering primitives shared by every php-* pattern in PolyPrism — a Prisma 6 & 7 generator that emits typed code from your schema.prisma in whichever shape fits the layer you're writing.

Pure ESM, Prisma 7-native, zero third-party runtime dependencies on any published @polyprism/* package.

You're probably looking for a pattern package

You don't install @polyprism/php-shared directly — each php-* pattern package pulls it in transitively.

| Install | What it emits | |---|---| | @polyprism/php-class | final class User { ... } — PHP 8.1+, mutable, public typed properties via constructor property promotion | | @polyprism/php-readonly | final readonly class User { ... } — PHP 8.2+, immutable value objects | | @polyprism/php-domain-class | final class User { public string $email { set(...) { ... } } } — PHP 8.4+, property-hook setters that route @coerce / @normalise through the polyprism/runtime Composer package |

What lives here

The PHP-specific layer between @polyprism/core's language-agnostic IR and the per-pattern emitters:

  • emitPhpModels(ctx, opts) — the top-level pipeline. Walks the IR, renders enums and models, surfaces any emit-time diagnostics, and writes everything to <outputDir>/Enums/*.php + <outputDir>/Models/*.php.
  • renderPhpModel(opts) — emits one model file as a PHP class. Three declaration styles ("class", "readonly", "domain-class") share the same field-by-field type-mapping and PHPDoc emission; "domain-class" delegates to its own renderer (property hooks need a different shape from constructor property promotion).
  • renderPhpDomainClass(opts) — emits the PHP 8.4 property-hook variant used by @polyprism/php-domain-class. Setter pipelines route @coerce / @normalise through Polyprism\Runtime\Coerce and Polyprism\Runtime\Normalise (from the Composer-published polyprism/runtime package).
  • resolvePhpCoerceDecision — PHP-flavoured wrapper around @polyprism/core's language-neutral resolveCoerceKind. Returns the widened PHP setter input type (int|string, \DateTimeImmutable|string|int, etc.) plus the matching runtime method.
  • renderPhpEnum(opts) — emits a PHP 8.1+ backed enum (enum Role: string { case ADMIN = 'ADMIN'; }).
  • mapFieldPhpType — IR field → PHP type expression. Handles scalars, enums, relations, nullability, lists (with PHPDoc @var array<int, T> hints), and resolves @json references to generated value classes.
  • renderPhpJsonType — Parses a TS-shaped inline @json expression (a small supported subset) and emits a final readonly class for it. Nested objects collapse to PHPDoc array{...} shapes rather than spawning sub-classes.
  • UseCollector — deduped, sorted use-statement builder. Skips same-namespace references automatically.
  • renderPhpDoc + collectFieldExtraTags — PHPDoc emission for /// docs, @deprecated tags, native-type metadata, and list-element hints.
  • phpSingleQuote + phpNormaliseOpConstant + formatPhpDefault — small literal-formatting helpers shared between render-model.ts and render-domain-class.ts.

What's NOT in here (v0 scope)

  • TS unions / generics / identifier references inside an inline @json shape — fall back to mixed with a warning. Use @type("\\App\\YourType") to point at a hand-written PHP class for richer typing.
  • Bare and with-path @json forms (e.g. @json(SomeType), @json(SomeType from "./path")) — these rely on TS module imports that don't translate to PHP autoloading. Warn + fall back to mixed.
  • Source-position line numbers on diagnostics — DMMF doesn't expose them, so issues carry Model.field context strings instead.
  • A php-interface emitter for shape-contract interfaces (PHP 8.4 supports abstract property declarations on interfaces, but the idiomatic PHP DTO is a final readonly class — deferred until a real user asks).
  • A php-type emitter — not possible: PHP has no type-alias syntax at the language level.

Why this is split out from @polyprism/core

@polyprism/core is deliberately language-agnostic — IR, Prisma schema reader, annotation parser, naming resolver, the language-neutral coerce-rules decision matrix, diagnostic surface, and ident-lookup builders. @polyprism/php-shared is where PHP-specific concerns live. All three PHP pattern packages share one PHP rendering layer, so they agree on type mapping, use-statement handling, and PHPDoc by construction — not by convention.

Links

License

MIT © Travis Fitzgerald