eluceo / ical
The eluceo/iCal package offers an abstraction layer for creating iCalendars. You can easily create iCal files by using PHP objects instead of typing your *.ics file by hand. The output will follow RFC 5545 as best as possible.
Installs: 12 912 810
Dependents: 50
Suggesters: 2
Security: 0
Stars: 1 129
Watchers: 32
Forks: 162
Open Issues: 59
Requires
- php: >=7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-mbstring: *
- symfony/deprecation-contracts: ^2.1 || ^3.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.23.1
- friendsofphp/php-cs-fixer: ^3.4
- infection/infection: ^0.23 || ^0.26 || ^0.27
- phpmd/phpmd: ^2.13
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.8 || ^5.0
Conflicts
- php: 7.4.6
- 2.x-dev
- 2.14.0
- 2.13.0
- 2.12.1
- 2.12.0
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 0.x-dev
- 0.18.0
- 0.17.0
- 0.16.1
- 0.16.0
- 0.15.1
- 0.15.0
- 0.14.0
- 0.13.0
- 0.12.1
- 0.12.0
- 0.11.x-dev
- 0.11.6
- 0.11.5
- 0.11.4
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.1
- 0.10.0
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-dependabot/npm_and_yarn/website/cross-spawn-7.0.6
- dev-dependabot/github_actions/thomaseizinger/create-release-2.0.0
- dev-dependabot/github_actions/thomaseizinger/keep-a-changelog-new-release-3.1.0
- dev-dependabot/composer/2.x/phpunit/phpunit-10.5.5
- dev-dependabot/github_actions/actions/deploy-pages-4
- dev-dependabot/github_actions/actions/upload-pages-artifact-3
- dev-attachment-property
- dev-X-MICROSOFT-CDO-ALLDAYEVENT
This package is auto-updated.
Last update: 2024-11-19 10:02:35 UTC
README
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.
Navigate through the project
- 📖 read the documentation
- 🐛 report a bug or suggest a feature
- 🙋 raise a question
- 💬 start a discussion
Installation
You can install this package by using Composer, running the following command:
composer require eluceo/ical
Version / Upgrade
The initial version was released back in 2012.
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 2.
Documentation
Visit ical.poerschke.nrw for complete 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 fromDomain
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 \Eluceo\iCal\Domain\Entity\Event();
2. Create a calendar domain entity
$calendar = new \Eluceo\iCal\Domain\Entity\Calendar([$event]);
3. Transform calendar domain object into a presentation object
$iCalendarComponent = (new \Eluceo\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 Eluceo\iCal\Domain\Entity\Event()) ->setSummary('Christmas Eve') ->setDescription('Lorem Ipsum Dolor...') ->setOccurrence( new Eluceo\iCal\Domain\ValueObject\SingleDay( new Eluceo\iCal\Domain\ValueObject\Date( \DateTimeImmutable::createFromFormat('Y-m-d', '2030-12-24') ) ) ); // 2. Create Calendar domain entity $calendar = new Eluceo\iCal\Domain\Entity\Calendar([$event]); // 3. Transform domain entity into an iCalendar component $componentFactory = new Eluceo\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.