Skip to content

Installation

phil/listings

Requirements

PackageVersionWhy
PHP8.5 or laterReadonly classes, typed constants, array_all(), new without parentheses.
ext-mbstringanyTitles and places are counted in characters, not bytes.
psr/clock^1.0The Responder reads the instant of a response or a decision on a PSR-20 clock.

Installing

composer require phil/listings

Declaring the kinds

Each kind of listing the application offers has one KindPolicy; KindPolicies holds them, each kind once.

use Phil\Listings\KindPolicies;
use Phil\Listings\KindPolicy;
use Phil\Listings\ListingKind;
use Phil\Listings\Moderation;

$policies = new KindPolicies([
    KindPolicy::of(ListingKind::of('classified')),
    KindPolicy::of(ListingKind::of('job'), lifetimeDays: 60, moderation: Moderation::BeforePublication, maxOpenResponses: 500),
    KindPolicy::of(ListingKind::of('partner'), minimumAge: 13, reportsToHide: 2),
]);
RuleDefaultBoundsWhat it does
lifetimeDays301 to 365How long a listing stays published, from its publication.
reminderDays30 to lifetimeDays − 1How many days before its expiry the author is reminded; 0 for no reminder.
extensionDays301 to 365How many days one extension adds.
maxExtensions30 to 52How many times a listing may be extended.
moderationAfterPublicationModerated before a listing is shown, or after, on reports.
reportsToHide31 to 100How many distinct members' reports hide a published listing.
minimumAgenone0 to 120The youngest age that may respond; a listing may ask for an older one.
acceptsResponsesyesWhether listings of the kind take responses at all.
maxOpenResponses1001 to 10 000How many pending and accepted responses one listing takes.

A value out of its bounds throws InvalidListing, so that a policy read from configuration fails when the application boots, not when a member posts.

Building the responder

use Phil\Listings\Responder;

$responder = new Responder($policies, $blockList, $memberAges, $responseStore, $clock);

The block list, the members' ages and the store of responses are the application's (Extension points). The responder keeps no state of its own between calls: it is safe to share across the requests of a long-running worker.