kiefernwald/affair

A library to allow handling of events.

v1.4.1 2021-10-02 09:06 UTC

This package is auto-updated.

Last update: 2024-04-29 03:54:04 UTC


README

Build Status

Affair is a simple library to take away some work when handling events. It is the core of Oberhavel.jetzt project.

Installation

composer require kiefernwald/affair

Usage

Implement your own EventProvider, following EventProviderInterface. It should handle access to your storage:

<?php

use Carbon\Carbon;
use Kiefernwald\Affair\Model\Event;
use Kiefernwald\Affair\Model\EventPlace;
use Kiefernwald\Affair\Services\AffairInterface;
use Kiefernwald\Affair\Services\EventProviderInterface;

class MyEventProvider implements EventProviderInterface {

    public function provideSingle(string $eventId): Event
    {
        // ...
    }

    public function provideMany(
        Carbon $start,
        Carbon $end,
        ?EventPlace $place = null,
        int $maxResults = AffairInterface::MAX_EVENTS
    ): array
    {
        // ...
    }

    public function storeEvent(Event $event)
    {
        // ...
    }
}

Instantiate the main service in your code and pass it an instance of your event provider:

    // ...

    $affair = new Affair(new MyEventProvider());

    // ...

Use the service's main methods:

  • getEvents to get a list of events
  • getEvent to get a single event by id
  • createEvent to create and store a new event