Revisions
The revision enum
Declare your revisions as a backed enum, order them, and describe them with
Your revisions are the cases of a backed enum of your application. Clients name a revision by its backed value, and
the library compares cases by their place in order().
Declare the enum
app/Api/ApiRevision.php
use Ark4ne\ApiRevisions\Revisions\IsRevision;
use Ark4ne\ApiRevisions\Revisions\Meta;
use Ark4ne\ApiRevisions\Revisions\Revision;
enum ApiRevision: string implements Revision
{
use IsRevision;
#[Meta('First published revision', publishedAt: '2025-06-01')]
case Genesis = 'genesis';
#[Meta(
'Totals become decimal strings',
publishedAt: '2025-12-01',
deprecatedAt: '2026-11-01',
sunsetAt: '2027-05-01',
)]
case Winter25 = 'winter-25';
#[Meta('Totals in cents, `state` renamed `status`')]
case Spring26 = 'spring-26';
public static function order(): array
{
return [self::Genesis, self::Winter25, self::Spring26];
}
}
order()is explicit, oldest first. The last case is the head: the shape your code declares.- Append each new revision at the end; never reorder
order().revision:checkverifies that it holds every case exactly once, and the lock that a published revision never moves. - The enum may be string- or int-backed, and case names are free. Declaration order does not matter, only
order(). - Set
enuminconfig/revisions.phpto the enum class.
Describe a revision
#[Meta] on a case takes a description and three days, all Y-m-d:
| Argument | Used by |
|---|---|
description | the export ($comment) and the changelog heading |
publishedAt | the export and the changelog |
deprecatedAt | the Deprecation response header, carrying that day (a future day announces it) |
sunsetAt | the Sunset response header, carrying that day |
#[Meta] never changes behaviour: a deprecated or sunset revision is still served.
Compare revisions
IsRevision gives every case these methods, all based on order():
| Method | Returns |
|---|---|
isBefore(R), isAfter(R) | strictly older, strictly newer than R |
isAtMost(R), isAtLeast(R) | R or older, R or newer |
previous(), next() | the neighbour in order(), null past the ends |
ApiRevision::latest(), ApiRevision::oldest() | the head, the oldest revision |
ApiRevision::current() | the revision of the running request or of the innermost using() |
ApiRevision::using(R, $callback) | runs the callback with R current, returns its result |
meta() | the case's #[Meta] (an empty one when none) |
Behaviour changes with no schema impact
A change of shape is always declared on the field (since(), until(), was()), never with an if. When a revision
changes a behaviour but no shape (a status code, a side effect, a rounding), read the current revision:
return OrderResource::make($order)
->response()
->setStatusCode(
ApiRevision::current()->isAtMost(ApiRevision::Winter25) ? 200 : 201,
);
JSON:API users find the same pattern under Guards.