Find a file
Anton Dachauer 84ee7161eb
All checks were successful
/ checks (8.1) (pull_request) Successful in 1m35s
/ checks (8.2) (pull_request) Successful in 54s
/ checks (8.3) (pull_request) Successful in 1m13s
/ checks (8.4) (pull_request) Successful in 47s
/ checks (8.5) (pull_request) Successful in 1m17s
/ security_checks (8.1) (pull_request) Successful in 1m20s
/ security_checks (8.2) (pull_request) Successful in 50s
/ security_checks (8.3) (pull_request) Successful in 58s
/ security_checks (8.4) (pull_request) Successful in 40s
/ security_checks (8.5) (pull_request) Successful in 54s
/ tests (8.1) (pull_request) Successful in 41s
/ tests (8.2) (pull_request) Successful in 1m2s
/ tests (8.3) (pull_request) Successful in 1m0s
/ tests (8.4) (pull_request) Successful in 40s
/ tests (8.5) (pull_request) Successful in 57s
/ sonarcube (pull_request) Successful in 22s
/ checks (8.1) (push) Successful in 55s
/ checks (8.2) (push) Successful in 1m33s
/ checks (8.3) (push) Successful in 1m9s
/ checks (8.4) (push) Successful in 46s
/ checks (8.5) (push) Successful in 1m7s
/ security_checks (8.1) (push) Successful in 1m20s
/ security_checks (8.2) (push) Successful in 43s
/ security_checks (8.3) (push) Successful in 41s
/ security_checks (8.4) (push) Successful in 59s
/ security_checks (8.5) (push) Successful in 1m2s
/ tests (8.1) (push) Successful in 41s
/ tests (8.2) (push) Successful in 1m0s
/ tests (8.3) (push) Successful in 41s
/ tests (8.4) (push) Successful in 1m4s
/ tests (8.5) (push) Successful in 40s
/ sonarcube (push) Successful in 33s
fix composer.json
2025-12-11 03:52:33 +01:00
.forgejo/workflows add sonarcube 2025-12-11 03:27:53 +01: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 PHP 8.5 compatibility 2025-12-11 02:31:33 +01:00
tests change namespace 2025-07-24 18:50:48 +02:00
.editorconfig add sonarcube 2025-12-11 03:27:53 +01: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 composer.json 2025-12-11 03:52:33 +01:00
composer.lock PHP 8.5 support 2025-12-10 12:59:05 +01: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 fix composer.json 2025-12-11 03:52:33 +01:00
sonar-project.properties add sonarcube 2025-12-11 03:27:53 +01: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.