Find a file
2025-09-11 11:25:17 +02:00
ci Fork from https://github.com/markuspoerschke/iCal 2025-06-21 13:16:57 +02:00
docs change namespace 2025-07-24 18:50:48 +02:00
examples change namespace 2025-07-24 18:50:48 +02:00
src change namespace 2025-07-24 18:50:48 +02:00
tests change namespace 2025-07-24 18:50:48 +02:00
.editorconfig fork from github https://github.com/markuspoerschke/iCal 2025-06-20 15:45:02 +02:00
.gitattributes fork from github https://github.com/markuspoerschke/iCal 2025-06-20 15:45:02 +02:00
.gitignore Fork from https://github.com/markuspoerschke/iCal 2025-06-21 13:16:57 +02:00
.gitlab-ci.yml trigger documentation deployment when release 2025-09-11 10:57:36 +02:00
CHANGELOG.md other: changelog update 2025-06-22 14:25:14 +02:00
composer.json fix version in composer.json 2025-09-11 11:25:17 +02:00
composer.lock change namespace 2025-07-24 18:50:48 +02:00
CONTRIBUTING.md Fork from https://github.com/markuspoerschke/iCal 2025-06-21 13:16:57 +02:00
LICENSE Fork from https://github.com/markuspoerschke/iCal 2025-06-21 13:16:57 +02:00
phpstan.neon Fork from https://github.com/markuspoerschke/iCal 2025-06-21 13:16:57 +02:00
phpunit.dist.xml #1 fix some deprecations 2025-07-07 13:04:51 +02:00
README.md trigger documentation deployment when release 2025-09-11 10:57:36 +02:00
UPGRADE.md change namespace 2025-07-24 18:50:48 +02:00

📅 iCal creator for PHP

pipeline status coverage report Latest Release

This package offers an abstraction layer for creating iCalendars files. By using this PHP package, you can create *.ics files without the knowledge of the underling format. The output itself will follow RFC 5545 as good as possible.

Note on the Fork

This is a fork (from version 2.14.0) of markuspoerschke/iCal by Markus Poerschke.

We have decided to host this project on our GitLab instance and will continue to support this package. To contribute, please create a free account.

Navigate through the project

Installation

You can install this package by using Composer, running the following command:

composer require opencal/ical

Version / Upgrade

The initial version was released back in 2012 (see https://github.com/markuspoerschke/iCal for history). The version 2 of this package is a complete rewrite of the package and is not compatible to older version. Please see the upgrade guide if you want to migrate from version 0.* to 2.*. If you just start using this package, you should install version 3.

Version PHP Version
3.* 8.1 - 8.4
2.* 7.4 - 8.3
0.16.* 7.0 - 8.2
0.11.* 5.3.0 - 7.4

Documentation

Visit the documentation.

Usage

The classes within this package are grouped into two namespaces:

  • The Domain contains the information about the events.
  • The Presentation contains the transformation from Domain into a *.ics file.

To create a calendar, the first step will be to create the corresponding domain objects. Then these objects can be transformed into a iCalendar PHP representation, which can be cast to string.

Empty event

In this very basic example, that renders an empty event. You will learn how to create an event domain object, how to add it to a calendar and how to transform it to a iCalendar component.

1. Create an event domain entity

$event = new \OpenCal\iCal\Domain\Entity\Event();

2. Create a calendar domain entity

$calendar = new \OpenCal\iCal\Domain\Entity\Calendar([$event]);

3. Transform calendar domain object into a presentation object

$iCalendarComponent = (new \OpenCal\iCal\Presentation\Factory\CalendarFactory())->createCalendar($calendar);

4. a) Save to file

file_put_contents('calendar.ics', (string) $iCalendarComponent);

4. b) Send via HTTP

header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="cal.ics"');

echo $iCalendarComponent;

Full example

The following example will create a single day event with a summary and a description. More examples can be found in the examples/ folder.

<?php

require_once __DIR__ . '/../vendor/autoload.php';

// 1. Create Event domain entity
$event = (new OpenCal\iCal\Domain\Entity\Event())
    ->setSummary('Christmas Eve')
    ->setDescription('Lorem Ipsum Dolor...')
    ->setOccurrence(
        new OpenCal\iCal\Domain\ValueObject\SingleDay(
            new OpenCal\iCal\Domain\ValueObject\Date(
                \DateTimeImmutable::createFromFormat('Y-m-d', '2030-12-24')
            )
        )
    );

// 2. Create Calendar domain entity
$calendar = new OpenCal\iCal\Domain\Entity\Calendar([$event]);

// 3. Transform domain entity into an iCalendar component
$componentFactory = new OpenCal\iCal\Presentation\Factory\CalendarFactory();
$calendarComponent = $componentFactory->createCalendar($calendar);

// 4. Set headers
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="cal.ics"');

// 5. Output
echo $calendarComponent;

License

This package is released under the MIT license.