adachsoft / reminder-json-file
JSON file repositories for adachsoft/reminder-contracts reminders and acknowledgements.
Requires
- php: ^8.3
- adachsoft/recurrence-contracts: ^0.1
- adachsoft/reference-contracts: ^0.1
- adachsoft/reminder-contracts: ^0.1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- adachsoft/recurrence: ^0.1.1
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/reminder-json-file provides JSON-file implementations of the reminder and acknowledgement repository contracts for small installations that need durable storage without a database.
Requirements
- PHP 8.3 or newer.
adachsoft/reminder-contracts^0.1.adachsoft/recurrence-contracts^0.1.adachsoft/reference-contracts^0.1.adachsoft/recurrence^0.1.1when using its built-in recurrence normalizer in the examples. It is a separate package; anyRecurrenceRuleNormalizerInterfaceimplementation can be used instead.
Installation
composer require adachsoft/reminder-json-file
Usage
Create each repository with the path to its JSON document. The reminder repository accepts a recurrence-rule normalizer; the acknowledgement repository does not need additional configuration:
use AdachSoft\Recurrence\RecurrenceFactory;
use AdachSoft\ReminderJsonFile\Repository\JsonAcknowledgementRepository;
use AdachSoft\ReminderJsonFile\Repository\JsonReminderRepository;
$reminderRepository = new JsonReminderRepository(
__DIR__ . '/var/reminders.json',
RecurrenceFactory::createNormalizer(),
);
$acknowledgementRepository = new JsonAcknowledgementRepository(
__DIR__ . '/var/acknowledgements.json',
);
RecurrenceFactory::createNormalizer() comes from the separately installed adachsoft/recurrence package. The adapter depends on the normalizer interface, so an implementation from another package can be supplied. The separately installed adachsoft/reminder package provides ReminderServiceFactory; configure that factory with these repositories through their ReminderRepositoryInterface and AcknowledgementRepositoryInterface contracts.
Examples
See Basic usage for a standalone example that saves a weekly reminder, acknowledges one occurrence for a principal, and reads the acknowledgement back.
File format
Reminder document
Reminder records are stored in an object keyed by reminder identifier. The rule value is stored exactly as returned by the configured normalizer; for repeating rules, the built-in normalizer uses the following fields:
{
"reminders": {
"weekly-check-in": {
"id": "weekly-check-in",
"owner": {
"type": "account",
"id": "alice"
},
"title": "Weekly check-in",
"recipients": [
{
"type": "account",
"id": "alice"
}
],
"rule": {
"type": "repeating",
"start": "2026-12-07T09:00:00",
"timezone": "UTC",
"frequency": "weekly",
"interval": 1,
"times": [],
"weekdays": [],
"month_days": [],
"weekday_occurrences": [],
"months": [],
"end": {
"type": "never"
},
"exceptions": [],
"additions": []
},
"createdAt": "2026-12-01T09:00:00.123456+00:00",
"updatedAt": "2026-12-01T09:00:00.123456+00:00",
"version": 1,
"message": null,
"repeat": {
"intervalMinutes": 30,
"maxRepeats": 3
},
"subject": null,
"enabled": true,
"metadata": {}
}
}
}
Reminder timestamps use ISO-8601 format Y-m-d\TH:i:s.uP. Recurrence-rule date fields follow the normalizer's local wall-clock format. Metadata is stored as a JSON object, including when it is empty.
Acknowledgement document
Acknowledgements are stored as a JSON list in insertion order. Each record contains the reminder identifier, exact occurrence key, principal reference, and acknowledgement timestamp:
{
"acknowledgements": [
{
"reminderId": "weekly-check-in",
"occurrenceKey": "2026-12-07T09:00:00+00:00",
"principal": {
"type": "account",
"id": "alice"
},
"acknowledgedAt": "2026-12-07T09:15:30.123456+00:00"
}
]
}
Acknowledgement timestamps use ISO-8601 format Y-m-d\TH:i:s.uP. Repeated saves for the same reminder, occurrence key, and principal keep the original acknowledgement and return false.
Concurrency
Reads use a shared flock lock and read-modify-write operations use an exclusive lock on a sidecar .lock file. Updates write a temporary file beside the document and atomically replace it. Acknowledgement duplicate detection and insertion take place in one locked update, so concurrent saves preserve the original acknowledgement. The two JSON documents are locked independently and are not a cross-document transaction.
Contract tests
Run each shared repository contract and its JSON-file-specific tests with:
vendor/bin/phpunit tests/Repository/JsonReminderRepositoryContractTest.php
vendor/bin/phpunit tests/Repository/JsonAcknowledgementRepositoryContractTest.php
The reminder test extends AdachSoft\ReminderContracts\Testing\AbstractReminderRepositoryContractTest; the acknowledgement test extends AdachSoft\ReminderContracts\Testing\AbstractAcknowledgementRepositoryContractTest.
Limits
Each operation reads or writes the complete JSON document. This adapter is intended for small installations and modest collections, not large datasets or high-throughput storage. Acknowledgements are retained until removeByReminder() is called.