Search by

phil / trust-levels

phil

Open rights to members as they earn trust, with no score shown: levels kept with grace, set by hand, gating groups, hiding and moderated pseudonyms.

0.1.0-alpha 2026-12-02 22:00 UTC

This package is auto-updated.

Last update: 2026-12-03 01:33:45 UTC


README

Members earn rights as they show trust, and never see a score: levels reached by their activity, kept with a margin and a grace, set by hand when needed, and opening privileges such as posting links, creating a group, hiding a content until the moderation reviews it, or speaking under a pseudonym the moderation can still lift.

phil/trust-levels gives an application — a community, a course platform, a club — the levels of trust of a forum without the karma. A ladder lists levels from the entry level up, what reaches each one and what keeps it; the privileges open at a level and above. The levels are named, never numbered on screen: a member sees what they may do, not a count to chase.

The application gives the member's activity — when they joined and counts of acts it measures, such as contributions approved or reports upheld — and asks for an evaluation. The member climbs as soon as the requirements are met, several levels at once. A level no longer kept is kept for a grace, then lost down to the highest level still kept; lower thresholds to keep a level than to reach it stop a member near a threshold from losing and regaining it at every evaluation. A newcomer is shown as new for a few days. A moderator grants a level, a floor the activity never takes the member below, or restricts a member, a ceiling applied at once, each with its reason.

Each change says which privileges it opened and closed, for the application to announce "you can now post links" or explain a loss, and is dispatched as a PSR-14 event.

Trusted members may wear a pseudonym per context: a keyed hash that stays the same in a course or a forum and cannot be linked from one context to another. The moderation is told the first time each is worn, and unmasks one with a reason, each time dispatched for the audit journal.

It is a plain PHP library on psr/clock and psr/event-dispatcher. The levels and the pseudonyms live in stores behind two interfaces, in memory for tests and scripts. It reads acts only, never what a member reads, holds no state between calls and runs in a worker. The pages, the database tables and the scheduled evaluations belong to the application or to a bundle.

Status

Part State
Ladders of named levels and privileges, built or read from configuration, with bounds and a fuzz target Implemented and tested
Requirements on counts of acts and on the age of the account, to reach and to keep a level Implemented and tested
Evaluation: climbs of several levels, margins, graces, falls to the highest level kept Implemented and tested
Grants as floors, restrictions as ceilings, releases, each with who, why and when Implemented and tested
Changes with the privileges opened and closed, dispatched as events; newcomers Implemented and tested
Pseudonyms per context for trusted members, recorded, unmasked with a reason and journaled Implemented and tested
In-memory stores Implemented and tested
A Symfony bundle: services from configuration, Doctrine stores, scheduled evaluations, the moderation adapter Not written

Documentation

Document What it covers
Installation Requirements, installing, building the services.
Levels The ladder and its format, requirements, evaluation, graces, newcomers, levels set by hand, changes.
Privileges Checking a privilege, the default privileges, creating a group, hiding a content for the moderation.
Pseudonyms Handles per context, the privilege, unmasking with a reason, the journal.
Extension points The ports, events and arguments an application chooses or replaces.
Testing The package's tests, fuzz target and benchmark, and how to test code that checks trust.
Reference Every public type, with its role.

Quick start

composer require phil/trust-levels
use Phil\TrustLevels\Activity;
use Phil\TrustLevels\InMemoryTrustStore;
use Phil\TrustLevels\Privilege;
use Phil\TrustLevels\TrustLadder;
use Phil\TrustLevels\TrustLevels;
use Symfony\Component\Clock\NativeClock;

$trust = new TrustLevels(TrustLadder::default(), new InMemoryTrustStore(), new NativeClock());

$change = $trust->evaluate('member-7', new Activity($joinedAt, ['approved_contributions' => 3]));
// $change->to === 'basic', $change->unlocked === ['post_links', 'post_images']

$trust->allows('member-7', Privilege::POST_LINKS);   // true
$trust->allows('member-7', Privilege::CREATE_GROUP); // false until the level "member"

Requirements

PHP 8.5 or later with ext-mbstring.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.