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-readonly

v0.3.1

Published

Prisma 6 & 7 generator that emits PHP 8.2+ `final readonly class` value objects from your schema. Immutable DTOs with constructor property promotion. Pure ESM, zero runtime deps. Part of PolyPrism.

Downloads

438

Readme

@polyprism/php-readonly

Prisma 6 & 7 generator that emits PHP 8.2+ final readonly class value objects from your schema.prisma. Immutable DTOs with constructor property promotion. Part of PolyPrism.

generator polyprismCodegen {
  provider = "polyprism-php-readonly"
  output   = "../src/Generated"
}

That's the whole API. Pair it with a composer.json psr-4 mapping and you're done:

{
  "autoload": {
    "psr-4": { "Generated\\": "src/Generated/" }
  }
}

What it emits

<?php

declare(strict_types=1);

namespace Generated\Models;

use Generated\Enums\Role;

final readonly class User
{
    public function __construct(
        public string $id,
        public string $email,
        public ?string $name = null,
        public Role $role = Role::MEMBER,
        public \DateTimeImmutable $createdAt = new \DateTimeImmutable(),
    ) {}
}

Same shape as @polyprism/php-class, but the class is marked readonly — properties can be assigned in the constructor and never again. Try $user->email = 'x'; after construction and PHP throws Error: Cannot modify readonly property User::$email.

When to use this over php-class

  • You want value objects — DTOs that should never mutate after construction. Read-only enforcement at the language level means accidental writes get caught by the engine, not by code review.
  • You want safe sharing — readonly is the right shape for data you pass around without defensive copying: queue payloads, FFI handlers, event objects, anything that travels through a pipeline you don't fully own.
  • You're modelling events / value semantics — orders, payments, audit entries: things that, once recorded, shouldn't change.

Use @polyprism/php-class when you need to mutate properties in place (e.g. updating a status before saving). The two patterns are otherwise identical — same constructor signature, same property types, same use statements.

If you need setter-driven @coerce / @normalise behaviour (stringified Int columns from JSON bodies, email normalisation on assignment, etc.), use @polyprism/php-domain-class instead. PHP 8.4 property hooks plus the Composer-published polyprism/runtime runtime — the trade is one Composer dependency in exchange for active boundary normalisation.

Updating a readonly value

Use the with... pattern in your own code:

$user = new User(id: 'abc', email: '[email protected]');

// Can't do this — PHP throws Error:
// $user->email = '[email protected]';

// Do this instead:
$updated = new User(
    id: $user->id,
    email: '[email protected]',
    name: $user->name,
    role: $user->role,
    createdAt: $user->createdAt,
);

A future minor release may emit withX(): static methods automatically. For v0, the pattern is hand-written at the call site.

Everything else

Type mapping, annotation support, default handling, constructor ordering, file layout — identical to @polyprism/php-class. See that package's README for the full table.

Links

License

MIT © Travis Fitzgerald