cultuurnet / calendar-summary-v3
将 cultuurnet 日期转换为可读摘要的库
v4.0.8
2024-06-25 09:36 UTC
Requires
- php: ^7.4 || ^8.0
- ext-intl: *
- ext-json: *
- nesbot/carbon: ^2.63
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- publiq/php-cs-fixer-config: ^2.0
README
安装
composer require cultuurnet/calendar-summary-v3
工作原理
此库帮助格式化来自 Uitdatabank 的事件或地点的日历信息,作为 HTML 或纯文本。我们通过解析 JSONLD 中的 Offer
实例来完成此操作。
类型
Offer
对象有一个 calendarType
属性,可以有以下四个选项之一
- 单次
- 多次
- 周期性
- 永久
参数
有 3 个(可选)参数可以在表单初始化时使用。这些是
- langCode
- hidePastDates
- timeZone
langCode
(字符串) 默认值: 'nl_BE'。您可以使用此参数来更改格式化器生成的输出语言。目前支持 nl、fr、de 和 en。此处格式为标准 PHP 地区设置。例如 'fr_BE' 或 'de_BE'。
hidePastDates
(布尔值) 默认值: false。当此参数为 true 时,将仅在具有 calendarType 'multiple' 的报价中使用。当为 true 时,过去的日期将不会出现在格式化器的输出中。
timeZone
(字符串) 默认值: 'Europe/Brussels'。您可以使用此参数设置不同的时区。支持的时区可以在以下 列表 中找到。
格式
初始化格式化器后,您可以通过以下 2 个参数调用格式化方法
- 由本库提供的
Offer
对象的实例 - 所需的输出格式 ('xs', 'sm', 'md' 或 'lg')
使用不受支持的格式将抛出异常。
示例
<?php // Make sure to either deserialize the Event/Place from JSON, or set the necessary properties through setCalendarType() etc. $offer = new \CultuurNet\CalendarSummaryV3\Offer\Offer::fromJsonLd('JSONLD_STRING'); // This will format the calendar info of `$offer` in a medium HTML output $calendarHTML = new \CultuurNet\CalendarSummaryV3\CalendarHTMLFormatter('nl_BE', true, 'Europe/Brussels'); $calendarHTML->format($offer, 'md'); // This will format the calendar info of `$offer` in a large plain text output $calendarPlainText = new \CultuurNet\CalendarSummaryV3\CalendarPlainTextFormatter('fr_BE', true, 'Europe/Paris'); $calendarPlainText->format($offer, 'lg');