eluceo/ ical
eluceo/iCal包提供了创建iCalendar的抽象层。您可以通过使用PHP对象而不是手动输入*.ics文件来轻松创建iCalendar文件。输出将尽可能遵循RFC 5545。
2.14.0
2024-07-11 22:33 UTC
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/express-4.21.0
- 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-09-21 06:23:29 UTC
README
此包提供了创建iCalendar文件的抽象层。通过使用此PHP包,您可以创建*.ics文件,而无需了解底层格式。输出本身将尽可能遵循RFC 5545。
浏览项目
安装
您可以通过运行以下命令使用Composer安装此包
composer require eluceo/ical
版本 / 升级
最初版本是在2012年发布的。此包的版本2是对包的完全重写,并且与旧版本不兼容。如果您想从版本0.*
迁移到2.*
,请参阅升级指南。如果您刚开始使用此包,应安装版本2。
文档
访问ical.poerschke.nrw以获取完整文档。
用法
此包中的类分为两个命名空间
Domain
包含关于事件的信息。Presentation
包含将Domain
转换为 *.ics 文件的过程。
要创建日历,第一步是创建相应的域对象。然后可以将这些对象转换为iCalendar的PHP表示形式,然后将其转换为字符串。
空事件
在这个非常基本的示例中,它将渲染一个空事件。您将了解如何创建事件域对象,如何将其添加到日历中,以及如何将其转换为iCalendar组件。
1. 创建事件域实体
$event = new \Eluceo\iCal\Domain\Entity\Event();
2. 创建日历域实体
$calendar = new \Eluceo\iCal\Domain\Entity\Calendar([$event]);
3. 将日历域对象转换为表示对象
$iCalendarComponent = (new \Eluceo\iCal\Presentation\Factory\CalendarFactory())->createCalendar($calendar);
4. a) 保存到文件
file_put_contents('calendar.ics', (string) $iCalendarComponent);
4. b) 通过HTTP发送
header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); echo $iCalendarComponent;
完整示例
以下示例将创建一个具有摘要和描述的单日事件。更多示例可以在examples/文件夹中找到。
<?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;
许可协议
此包在MIT许可协议下发布。