Extension points
tilttek/homebrew-hubThe package is at 0.x: its extension points are stable only from its 1.0 release. Until then, a minor version may
change them, and its CHANGELOG says how.
| To | Do |
|---|---|
| Keep and find the homebrews | Implement Contract\HomebrewStore, and pass it to HomebrewHub and Adoption. |
| Keep which homebrews a table follows | Implement Contract\SubscriptionStore, and pass it to Adoption. |
| Keep an adoption whole | Implement Contract\Transactions, and pass it to Adoption. |
| Act on what happened | Implement Contract\HomebrewObserver, and pass it to the services. |
| Give the time | Pass a PSR-20 ClockInterface. |
| Say who may publish, remix, endorse, retire, adopt or drop | Check it in the application before calling the services. |
The homebrew store
Contract\HomebrewStore keeps the homebrews, each at a version:
homebrew()gives one by its identifier, or null;save()keeps one at the next version and returns it. One at version 0 is new, and the store has none of its identifier; any other is kept only when the store holds it at that version, andHomebrewConflictis raised otherwise, nothing kept;search()gives the homebrews that answer aHomebrewSearch, in its order, the page it asks:HomebrewSearch::matches()andHomebrewSearch::compare()say which and in what order, and a store in a database writes the same as a query — the game system of the latest release, a tag, the author, retired or not; the count of endorsements, then the moment of the latest release, then the identifier.
Two members endorse a homebrew at once and both read version 7: the first save keeps version 8, and the second is
refused with HomebrewConflict; read anew, the endorsement is made again.
A homebrew holds strings, integers, moments, its tags and endorsers — lists of identifiers — its lineage — each origin
two strings, an integer, a title and a licence, whose value is its string case — and its releases. A release is a
version of tilttek/table-rules — a number, rules, variants, a system, a note, a moment and who published it — and a
licence. An application keeps the releases in their own table, one row per release, and the endorsers in another: the
store reads them with the homebrew.
Store\InMemoryHomebrewStore keeps them in memory, as long as the object lasts: it is for tests.
The subscription store
Contract\SubscriptionStore keeps which homebrews each table follows, each subscription at a version:
subscription()gives the subscription of a table to a homebrew, or null;subscriptions()gives those of a table, by identifier of the homebrew;save()keeps one at the next version, asHomebrewStore::save()does;remove()forgets one held at its version, and raisesHomebrewConflictotherwise.
Store\InMemorySubscriptionStore keeps them in memory, for tests.
The transactions
Adoption writes twice for one adoption or one drop: a version of the table's rules through TableRules, then the
subscription. Contract\Transactions::run() runs both as one: an application that keeps the rulebooks and the
subscriptions in one database runs the work inside a transaction, commits when it returns, rolls back and rethrows when
it throws. Store\NoTransactions runs the work as it comes; with it, a subscription refused after the table's rules were
published leaves those rules published.
The observer and its events
Contract\HomebrewObserver::notify() is told each fact once it is kept, by identifiers only:
| Event | When | Carries |
|---|---|---|
Event\ReleasePublished | A release was published; release 1 when the homebrew is new. | the release |
Event\HomebrewRemixed | A homebrew was made from a release of another one. | the source, its release |
Event\HomebrewEndorsed | A member endorsed a homebrew. | the member |
Event\EndorsementWithdrawn | A member withdrew their endorsement. | the member |
Event\HomebrewRetired | A homebrew was retired. | |
Event\HomebrewAdopted | A table adopted a release of a homebrew. | the table, the release |
Event\HomebrewDropped | A table stopped following a homebrew. | the table |
Every event implements Event\HomebrewEvent, whose homebrew is an identifier. A remix tells HomebrewRemixed, then
ReleasePublished of its release 1. A call that changes nothing tells nothing. An application sends a message from
them — through Messenger, with the identifiers alone — and reads the rest from the store: a notice to the tables that
follow a homebrew when a release is out, a notice to the author when a homebrew is remixed. TableRules tells its own
events of the version an adoption publishes, to its own observer.
The clock
The services read the time from the PSR-20 ClockInterface they are given, and from nothing else: the moment of a
release, of a retirement and of an adoption.
Who may do what
The services check what belongs to a homebrew: only its author publishes and retires it, an author does not endorse their own homebrew, and a remix keeps to the licence of its source. They trust their caller to say who is calling, and who may change the rules of a table — its game master, as a rule.