Search by

adachsoft / calendar

Arkadiusz Adach

Calendar logic for adachsoft/calendar-contracts: calendar service with access policy, recurring entries expanded into occurrences for day/week/month views, shared with accounts and groups via principal-contracts.

Package info

gitlab.com/a.adach/calendar

Issues

pkg:composer/adachsoft/calendar

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.1 2026-11-23 19:25 UTC

This package is auto-updated.

Last update: 2026-11-23 18:25:48 UTC


README

adachsoft/calendar is the application service for calendars and recurrence-aware entries. It enforces calendar access rules, persists changes through repository contracts, expands occurrences for date-range queries, and publishes change notifications. Storage and framework integration are provided by adapters, not by this package.

Requirements and installation

  • PHP 8.3 or later
  • adachsoft/calendar-contracts
  • adachsoft/recurrence-contracts and adachsoft/recurrence
  • adachsoft/principal-contracts
  • adachsoft/reference-contracts
  • psr/clock

Install with Composer:

composer require adachsoft/calendar

Usage

Quick start

The in-memory repositories are useful for tests and short-lived examples. They do not persist data between processes.

<?php

declare(strict_types=1);

use AdachSoft\Calendar\CalendarServiceFactory;
use AdachSoft\CalendarContracts\InMemory\InMemoryCalendarRepository;
use AdachSoft\CalendarContracts\InMemory\InMemoryEntryRepository;
use AdachSoft\PrincipalContracts\CompositeMembershipResolver;
use AdachSoft\ReferenceContracts\PrincipalReference;

$service = CalendarServiceFactory::create(
    new InMemoryCalendarRepository(),
    new InMemoryEntryRepository(),
    new CompositeMembershipResolver([]),
);

$owner = new PrincipalReference('account', 'alice');
$calendar = $service->createCalendar($owner, 'Personal', new \DateTimeZone('UTC'));

See the family calendar example for sharing with a group, adding weekly and all-day entries, querying a week, and cancelling one occurrence.

Access rules

PrincipalViewEdit entriesManage calendar
Owner (including a member of an owner group)YesYesYes
Shared principal or its transitive membersYesYesNo
Other principalsNoNoNo

The default MembershipCalendarAccessPolicy resolves the actor and its direct or transitive principal memberships through PrincipalMembershipResolverInterface. Calendar ownership may belong to an account or a group.

No-op behavior

An unchanged trimmed calendar name, sharing with the owner or an existing recipient, unsharing a non-recipient, an entry update with unchanged values, moving an entry to its current calendar, and cancelling an already cancelled occurrence are no-ops. They return the current DTO without incrementing its version, saving it, or notifying the listener. Passing null for entry metadata during an update keeps the stored metadata.

Change notifications

An optional CalendarChangeListenerInterface receives notifications after successful persistence. Creation notifications use a null before value; deletion notifications use a null after value. Deleting a calendar notifies the listener about each removed entry and then the calendar. No-op operations do not notify it.

Storage adapters

Implement CalendarRepositoryInterface and EntryRepositoryInterface to connect a database or another storage engine. Repositories own persistence and optimistic concurrency; the service package does not include a production storage adapter. Adapter authors can use the reusable repository contract tests provided by adachsoft/calendar-contracts/testing.

Custom infrastructure

CalendarServiceFactory::create() accepts custom change listeners, PSR-20 clocks, identifier generators, and recurrence calculators. To use a custom CalendarAccessPolicyInterface or different recurrence limits, construct CalendarService with the desired policy, ActivePeriodCalculator, and OccurrenceExpander.

Out of scope

This package does not edit an individual occurrence independently of its recurrence rule, manage invitations, synchronize with external calendars, or provide a web/mobile API. External calendar synchronization and application-specific invitation flows belong in adapters or higher-level services.