kiefernwald / affair
A library to allow handling of events.
v1.4.1
2021-10-02 09:06 UTC
Requires
- php: >=7.3
- nesbot/carbon: ^2.53
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
README
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 eventsgetEvent
to get a single event by idcreateEvent
to create and store a new event