phil / milestones
Unlock a goal's milestones as its counter grows (amount, people, day, entered value), and make an item only on enough orders before a deadline.
Requires
- php: >=8.5
Requires (Dev)
- phpunit/phpunit: ^13.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 02:52:34 UTC
README
Unlock a goal's milestones as its counter grows, and make an item only when enough orders come in before a deadline.
phil/milestones is a plain PHP library for collective goals: the stretch goals of a fundraiser, the sign-ups that open a second session, the hours a cohort learns together, the day-by-day rewards of a campaign. A goal counts one thing and holds milestones at thresholds of that count; the library says which milestones the counter reaches, unlocks them, and tells what the page should show. The application keeps the counter, the milestones' titles and rewards, and the stored unlocks.
- Four counters: an amount in the smallest unit of its currency, a number of people, the day of the goal worked out from its start in the start's time zone, or a value an administrator enters.
- Unlocked on their own or by an administrator: an automatic milestone unlocks as soon as the counter reaches it; another waits in a list for an administrator's approval, and an administrator may unlock any milestone early.
- Never unlocked twice: the first instant is kept, a counter that goes down after a refund locks nothing again,
and each unlock gives one
MilestoneUnlockedevent, with identifiers only, for the application to announce or reward. - Published or hidden: a hidden milestone is a surprise, out of what the public sees and of the next milestone until it unlocks.
- Rewards that last or end with the goal: once the goal closes, nothing unlocks any more; a kept reward, such as an announcement or an added chapter, stays, and a reward that lasts until the close, such as a discount, ends.
- The next milestone: what the counter still needs and how far it is, from 0 to 99 %.
- Production thresholds: an item made only on enough orders before a deadline is open, confirmed or cancelled.
- Stored unlocks that fail loudly: a short JSON text within a size limit; a damaged text is refused rather than read as fewer unlocks, which would announce them again.
- Worker-safe: every type is an immutable value, so one long-running worker serves any number of goals.
Status
| Part | State |
|---|---|
| Milestones, goals and the four counters | Implemented and tested |
| Advancing, unlocking by administration, events | Implemented and tested |
| Progress: reached, awaiting approval, visible, next, rewards | Implemented and tested |
| Stored unlocks and closing | Implemented and tested, fuzzed |
| Production thresholds | Implemented and tested |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements, installing, a first goal. |
| Goals and milestones | Counters, thresholds, unlocking, visibility and reward terms. |
| Unlocks | Advancing the counter, an administrator's unlock, events, closing and storing. |
| Progress | What a goal page shows: reached, awaiting approval, visible, next and rewards. |
| Production thresholds | An item made only on enough orders before a deadline. |
| Extension points | What an application may replace or add, and what is stable. |
| Testing | The tests, the fuzz target and the benchmark. |
| Reference | Every public type, with its role. |
Quick start
composer require phil/milestones
use Phil\Milestones\CounterKind; use Phil\Milestones\Goal; use Phil\Milestones\Milestone; use Phil\Milestones\Unlock; use Phil\Milestones\Unlocks; $goal = new Goal('spring-drive', CounterKind::Amount, [ new Milestone('new-chapter', 500_000), // 5,000.00 in cents new Milestone('second-cohort', 1_000_000, Unlock::ByAdministration), ]); $advance = $goal->advance($totalInCents, Unlocks::fromString($row->unlocks), $clock->now()); if ($advance->changed()) { $row->unlocks = $advance->unlocks->toString(); foreach ($advance->events as $event) { $dispatcher->dispatch($event); } } $progress = $goal->progress($totalInCents, $advance->unlocks); $progress->next(); // the next milestone to show $progress->percentToNext(); // how far the counter is towards it
Requirements
PHP 8.5 or later.
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.