adachsoft / reminder-contracts
PHP contracts and immutable models for reminders addressed to principals, recurrence rules, repeat-until-acknowledged policies, acknowledgements, repositories, access policies, and change notifications.
Requires
- php: ^8.3
- adachsoft/recurrence-contracts: ^0.1
- adachsoft/reference-contracts: ^0.1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
- phpunit/phpunit: Required to run the reusable repository contract tests from testing/
Provides
None
Conflicts
None
Replaces
None
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-contractsandadachsoft/recurrence-contracts, installed automatically as runtime dependencies.
Model overview
ReminderDtois the versioned reminder aggregate. It contains itsReminderId, owner, non-empty recipient collection, title, recurrence rule, timestamps, version, and optional message, repeat policy, subject, enabled flag, and metadata.RepeatPolicyDtoconfigures repeated notifications for an occurrence:intervalMinutesis between 1 and 1440, andmaxRepeatsis between 1 and 100. A null policy means one notification per occurrence.AcknowledgementDtorecords one leaf principal's acknowledgement of one reminder occurrence. Acknowledgements are identified by reminder, occurrence key, and principal.PrincipalReferenceandSubjectReferencecome fromadachsoft/reference-contracts. Recurrence rules come fromadachsoft/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(), andacknowledgements().ACKNOWLEDGE:acknowledge().MANAGE:updateReminder(),enable(),disable(), anddeleteReminder().
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.