Search by

adachsoft / reminder-json-file

Arkadiusz Adach

JSON file repositories for adachsoft/reminder-contracts reminders and acknowledgements.

Package info

gitlab.com/a.adach/reminder-json-file

Issues

pkg:composer/adachsoft/reminder-json-file

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-24 18:36 UTC

This package is auto-updated.

Last update: 2026-11-24 17:36:30 UTC


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.1 when using its built-in recurrence normalizer in the examples. It is a separate package; any RecurrenceRuleNormalizerInterface implementation 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.