Search by

adachsoft / item-list-json-file

Arkadiusz Adach

A JSON file-backed repository for generic item lists.

Package info

gitlab.com/a.adach/item-list-json-file

Issues

pkg:composer/adachsoft/item-list-json-file

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-24 16:02 UTC

This package is auto-updated.

Last update: 2026-11-24 15:02:49 UTC


README

adachsoft/item-list-json-file provides a JSON-file implementation of AdachSoft\ItemListContracts\Repository\ItemListRepositoryInterface for small installations that need durable item-list storage without a database.

Requirements

  • PHP 8.3 or newer.
  • adachsoft/item-list-contracts ^0.1.
  • adachsoft/reference-contracts ^0.1.

Installation

composer require adachsoft/item-list-json-file

Usage

Create the repository with the path to its JSON document and use it wherever an ItemListRepositoryInterface is required:

use AdachSoft\ItemListContracts\Repository\ItemListRepositoryInterface;
use AdachSoft\ItemListJsonFile\Repository\JsonItemListRepository;

$repository = new JsonItemListRepository(__DIR__ . '/var/item-lists.json');

// Pass $repository to an application service that requires ItemListRepositoryInterface.

The adachsoft/item-list package, which provides item-list application services and an ItemListServiceFactory, is installed separately. This adapter only provides the repository implementation and does not install that package.

Examples

See Basic usage for a standalone example that saves a list with two items and reads it back.

File format

The document stores item lists in an object keyed by list identifier:

{
    "lists": {
        "weekly-shopping": {
            "id": "weekly-shopping",
            "name": "Weekly shopping",
            "owner": {
                "type": "account",
                "id": "alice"
            },
            "sharedWith": [
                {
                    "type": "account",
                    "id": "bob"
                }
            ],
            "items": [
                {
                    "id": "apples",
                    "text": "Apples",
                    "position": 0,
                    "quantity": "6",
                    "note": null,
                    "checked": false,
                    "checkedAt": null,
                    "checkedBy": null,
                    "metadata": {}
                }
            ],
            "createdAt": "2025-05-04T08:09:10.123456+00:00",
            "updatedAt": "2025-05-04T08:09:10.123456+00:00",
            "version": 1,
            "subject": null,
            "metadata": {}
        }
    }
}

Dates use the ISO-8601 format Y-m-d\TH:i:s.uP. Metadata is stored as a JSON object, including when it is empty.

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. Repository saves also use optimistic versions: a new list must start at version 1, and an update is accepted only when the stored version (or 0 for a missing list) equals the new version minus one. Stale updates throw ConcurrentModificationException without replacing the document.

Contract tests

Run the repository contract and its JSON-file-specific tests with:

vendor/bin/phpunit tests/Repository/JsonItemListRepositoryContractTest.php

The contract test extends the shared AdachSoft\ItemListContracts\Testing\AbstractItemListRepositoryContractTest suite.

Limits

Each operation reads or writes the complete JSON document. This adapter is intended for small installations and modest item-list collections, not large datasets or high-throughput storage.