- PHP 99.5%
- Shell 0.5%
|
All checks were successful
/ checks (8.4) (pull_request) Successful in 31s
/ checks (8.2) (pull_request) Successful in 47s
/ checks (8.5) (pull_request) Successful in 32s
/ checks (8.3) (pull_request) Successful in 1m21s
/ checks (8.1) (pull_request) Successful in 1m28s
/ security_checks (8.2) (pull_request) Successful in 33s
/ security_checks (8.1) (pull_request) Successful in 49s
/ tests (8.1) (pull_request) Successful in 54s
/ security_checks (8.5) (pull_request) Successful in 58s
/ security_checks (8.4) (pull_request) Successful in 1m18s
/ security_checks (8.3) (pull_request) Successful in 1m36s
/ tests (8.3) (pull_request) Successful in 27s
/ tests (8.2) (pull_request) Successful in 49s
/ tests (8.4) (pull_request) Successful in 1m11s
/ tests (8.5) (pull_request) Successful in 1m30s
/ checks (8.3) (push) Successful in 37s
/ security_checks (8.1) (push) Successful in 33s
/ checks (8.1) (push) Successful in 1m33s
/ checks (8.2) (push) Successful in 1m34s
/ security_checks (8.2) (push) Successful in 34s
/ security_checks (8.5) (push) Successful in 27s
/ security_checks (8.3) (push) Successful in 1m5s
/ security_checks (8.4) (push) Successful in 1m9s
/ tests (8.1) (push) Successful in 33s
/ tests (8.2) (push) Successful in 42s
/ tests (8.3) (push) Successful in 1m3s
/ checks (8.5) (push) Successful in 1m22s
/ checks (8.4) (push) Successful in 2m45s
/ tests (8.5) (push) Successful in 28s
/ tests (8.4) (push) Successful in 1m14s
|
||
|---|---|---|
| .forgejo/workflows | ||
| ci | ||
| docs | ||
| examples | ||
| src | ||
| tests | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| CHANGELOG.md | ||
| composer.json | ||
| composer.lock | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| phpstan.neon | ||
| phpunit.dist.xml | ||
| README.md | ||
| sonar-project.properties | ||
| UPGRADE.md | ||
📅 iCal creator for PHP
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
Domaincontains the information about the events. - The
Presentationcontains the transformation fromDomaininto a*.icsfile.
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.