brainformatik / caldav-framework
Brainformatik CalDAV 框架
1.2.2
2021-02-10 10:33 UTC
Requires
- php: >=7.0
- ext-curl: *
- sabre/dav: 3.2.0
- sabre/vobject: 4.1.2
Requires (Dev)
- phpunit/phpunit: ~5.7.0
README
CalDAV 的 PHP 框架
此框架抽象了所有 VCALENDAR 实体。此外,它还会自动为日期添加所需的时间信息。您可以简单地使用 PHP DateTime 和 DateTimeZone 对象。
在创建事件或待办事项并设置所有必需的值之后,您可以创建 vcalendar 输出或将条目直接保存。
通过 composer 安装
首先,下载并安装 composer: Composer.
接下来,运行 composer 命令以安装 CalDAV 框架的最新稳定版本
composer require brainformatik/caldav-framework
手动安装
首先,下载 CalDAV 框架的最新版本: CalDAV 框架.
接下来,解压缩并将此包移动到您的应用程序结构中。
最后,使用包自动加载器来加载 CalDAV 框架类
<?php require_once 'caldav-framework/autoload.php';
示例用法
require_once('autoload.php'); try { $client = new \Brainformatik\CalDAV\Connection\Client([ 'baseUri' => 'http://some-url' // set caldav server url ]); $calendar = new \Brainformatik\CalDAV\Entity\Calendar($client, 'http://url-to-calendar'); $event = $calendar->addEvent(); $event->setUid('unique-id123415'); $event->setSummary('This is the summary'); $event->setDescription('This is the description which can be very long and should be folded at some point if the implementation is working correctly.'); $event->setComment('This is the comment you can use for something.'); $event->setLocation('Meeting room 1'); $event->setPriority(9); $event->addResources(['BEAMER', 'Flipchart']); $event->setStatus(\Brainformatik\CalDAV\Enum\EventStatus::CONFIRMED); $event->setDateEnd(new DateTime('2016-01-01 14:00:10', new DateTimeZone('America/New_York'))); $event->setDateStart(new DateTime('2015-12-12', new DateTimeZone('America/New_York'))); $event->setRecurrenceId(new DateTime('2015-12-12', new DateTimeZone('America/New_York')), [ 'RANGE' => 'THISANDFUTURE', 'VALUE' => 'DATE' ]); $duration = new \Brainformatik\CalDAV\Type\Duration(); $duration->setHour(10)->setMinute(30); $event->setDuration($duration); $event->setTransparency(\Brainformatik\CalDAV\Enum\EventTransparency::TRANSPARENT); $event->addExceptionDates([ new DateTime('2015-12-12 12:00:00', new DateTimeZone('America/New_York')), new DateTime('2015-12-13 12:00:00', new DateTimeZone('America/New_York')), new DateTime('2015-12-14 12:00:00', new DateTimeZone('Europe/Berlin')) ]); $event->setDateCreated(new DateTime('2016-10-08 09:32:00', new DateTimeZone('UTC'))); $event->setDateLastModified(new DateTime('2016-10-08 09:32:00', new DateTimeZone('UTC'))); // to get the icalendar output echo $calendar->serialize(); // to save the event to the calendar $calendar->save('filename.ics'); } catch (\Exception $e) { echo $e->getMessage(); }