Search by

adachsoft / reminder-contracts

Arkadiusz Adach

PHP contracts and immutable models for reminders addressed to principals, recurrence rules, repeat-until-acknowledged policies, acknowledgements, repositories, access policies, and change notifications.

Package info

gitlab.com/a.adach/reminder-contracts

Issues

pkg:composer/adachsoft/reminder-contracts

Statistics

Installs: 7

Dependents: 2

Suggesters: 0

Stars: 0

v0.1.0 2026-11-24 09:20 UTC

This package is auto-updated.

Last update: 2026-11-24 08:21:09 UTC


README

adachsoft/reminder-contracts provides framework-independent contracts, immutable models, in-memory repositories, and reusable repository contract tests for reminders addressed to accounts, groups, or other principals.

A reminder can concern any subject, follow a recurrence rule, and repeat notifications until each recipient acknowledges an occurrence. This package defines the data and storage contracts only; scheduling, notification delivery, and the reminder service implementation belong to adachsoft/reminder.

Installation

composer require adachsoft/reminder-contracts

Requirements

  • PHP 8.3 or later (^8.3).
  • adachsoft/reference-contracts and adachsoft/recurrence-contracts, installed automatically as runtime dependencies.

Model overview

  • ReminderDto is the versioned reminder aggregate. It contains its ReminderId, owner, non-empty recipient collection, title, recurrence rule, timestamps, version, and optional message, repeat policy, subject, enabled flag, and metadata.
  • RepeatPolicyDto configures repeated notifications for an occurrence: intervalMinutes is between 1 and 1440, and maxRepeats is between 1 and 100. A null policy means one notification per occurrence.
  • AcknowledgementDto records one leaf principal's acknowledgement of one reminder occurrence. Acknowledgements are identified by reminder, occurrence key, and principal.
  • PrincipalReference and SubjectReference come from adachsoft/reference-contracts. Recurrence rules come from adachsoft/recurrence-contracts.

The complete constructor and invariant contracts are documented in the public classes under src/Model/.

Occurrence keys

Use the exact key produced by OccurrenceDto::key() in adachsoft/recurrence-contracts when storing or querying an acknowledgement. Keys use the UTC form Y-m-d\TH:i:s\Z, for example 2026-12-01T07:00:00Z. The reminder contracts validate keys as non-empty strings without whitespace and with a maximum of 100 Unicode characters.

Repositories and persistence adapters

ReminderRepositoryInterface provides reminder lookup and persistence with optimistic concurrency: a new reminder is stored at version 1, and each update must be the next version. It also supports searches by principal and subject. AcknowledgementRepositoryInterface provides idempotent acknowledgement storage; saving the same reminder/occurrence/principal identity again keeps the original acknowledgement.

The included InMemoryReminderRepository and InMemoryAcknowledgementRepository are simple implementations for tests and examples. A persistent adapter should store recurrence rules through RecurrenceRuleNormalizerInterface from adachsoft/recurrence-contracts, rather than inventing a package-specific rule serialization format.

Running repository contract tests in an adapter package

An adapter package can extend the abstract contract test and return a fresh, empty repository from createRepository(). The example below uses this package's real in-memory implementation; an adapter package keeps the same test structure and returns its own concrete adapter instance, constructed with that adapter's dependencies.

use AdachSoft\ReminderContracts\InMemory\InMemoryReminderRepository;
use AdachSoft\ReminderContracts\Repository\ReminderRepositoryInterface;
use AdachSoft\ReminderContracts\Testing\AbstractReminderRepositoryContractTest;

final class InMemoryReminderRepositoryContractTest extends AbstractReminderRepositoryContractTest
{
    protected function createRepository(): ReminderRepositoryInterface
    {
        return new InMemoryReminderRepository();
    }
}

Create the corresponding subclass of AbstractAcknowledgementRepositoryContractTest for an acknowledgement adapter, implementing its createRepository(): AcknowledgementRepositoryInterface method. With PHPUnit installed and the adapter test directory configured in phpunit.xml, run the contracts with:

vendor/bin/phpunit

The abstract test classes are autoloaded under AdachSoft\ReminderContracts\Testing\.

Access policy

ReminderAccessPolicyInterface is the policy boundary used by the service. The required operations are:

  • VIEW: getReminder(), remindersFor(), remindersForSubject(), and acknowledgements().
  • ACKNOWLEDGE: acknowledge().
  • MANAGE: updateReminder(), enable(), disable(), and deleteReminder().

The informative default policy in adachsoft/reminder allows owners and recipients (including access through group membership) to view and acknowledge reminders; only the owner may manage a reminder. Creating a reminder assigns the acting principal as its owner.

Service and change events

ReminderServiceInterface defines the application API for creating, retrieving, listing, updating, enabling, disabling, deleting, acknowledging, and reading acknowledgements. Its implementation is provided by adachsoft/reminder, not by this contracts package. A persisted reminder change advances its version and updates updatedAt; enabling an already enabled reminder, disabling an already disabled reminder, or applying an identical update is a no-op that returns the current reminder without saving or notifying the listener. A repeated acknowledgement returns the stored acknowledgement and does not emit a new acknowledgement event.

ReminderChangeListenerInterface separates change notifications from persistence. It reports a created, changed, or deleted reminder through onReminderChanged(), and reports a newly stored acknowledgement through onAcknowledged().

The adachsoft/reminder implementation coordinates these contracts with its scheduling/automation and notification integrations. Neither scheduling nor message delivery is performed by this package.

Basic usage

See docs/examples/basic-usage.md for a runnable weekly group-reminder example using only this package and its dependencies.