https://github.com/xp-forge/ical
Calendar and events
https://github.com/xp-forge/ical
calendar ical php xp-framework
Last synced: 8 months ago
JSON representation
Calendar and events
- Host: GitHub
- URL: https://github.com/xp-forge/ical
- Owner: xp-forge
- Created: 2016-06-22T13:42:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-24T10:45:09.000Z (about 2 years ago)
- Last Synced: 2025-03-12T23:02:12.451Z (about 1 year ago)
- Topics: calendar, ical, php, xp-framework
- Language: PHP
- Size: 164 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
iCal: Calendar and events
=========================
[](https://github.com/xp-forge/ical/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagist.org/packages/xp-forge/ical)
I/O
---
Calendars can be read and written using the ICalendar class
```php
use text\ical\ICalendar;
use util\cmd\Console;
use io\File;
$ical= new ICalendar();
$calendar= $ical->read('BEGIN:VCALENDAR...');
$calendar= $ical->read(Console::$in->stream());
$calendar= $ical->read(new File('meeting.ics'));
$ical->write($calendar, Console::$out->stream());
$ical->write($calendar, new File('meeting.ics'));
```
Events
------
Typically a calendar contains one event, though the format allows any number, including none at all.
Using first event, typical use-case:
```php
$event= $calendar->events()->first();
```
To prevent a `lang.ElementNotFoundException` when no event is present, check first:
```php
$events= $calendar->events();
if ($events->present()) {
$event= $events->first();
} else {
// Handle situation when no events are inside calendar
}
```
Process all events:
```php
foreach ($calendar->events() as $event) {
// ...
}
```
Creation
--------
Calendar instances can be created using a fluent interface
```php
use text\ical\{
Calendar,
Event,
Organizer,
Attendee,
IDate,
Text,
Method,
Role,
PartStat
};
$calendar= Calendar::with()
->method(Method::REQUEST)
->prodid('Microsoft Exchange Server 2010')
->version('2.0')
->events([Event::with()
->organizer(new Organizer('The Organizer', 'MAILTO:organizer@example.com'))
->attendees([
Attendee::with()
->role(Role::CHAIR)
->partstat(PartStat::NEEDS_ACTION)
->rsvp('TRUE')
->cn('The Attendee 1')
->value('MAILTO:attendee2@example.com')
->create()
,
Attendee::with()
->role(Role::REQ_PARTICIPANT)
->partstat(PartStat::NEEDS_ACTION)
->rsvp('TRUE')
->cn('The Attendee 2')
->value('MAILTO:attendee3@example.com')
->create()
])
->dtstart(new IDate(null, '20160524T183000Z'))
->dtend(new IDate(null, '20160524T190000Z'))
->location(new Text('de-DE', 'BS 50 EG 0102'))
->summary(new Text('de-DE', 'Treffen'))
->create()
])
->create()
;
```