beastbytes/icalendar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

beastbytes/icalendar

Composer 安装命令:

composer require beastbytes/icalendar

包简介

Create, edit, and import iCalendar

README 文档

README

The iCalendar library provides the ability to create, edit, and import RFC 5545 - Internet Calendaring and Scheduling (iCalendar) including properties defined in RFC 7986 - New Properties for iCalendar.

Creating iCalendars

The iCalendar library allows creation of iCalendars in an object-oriented way.

To create an iCalendar, create a new Vcalendar object then add properties and components to it; properties and other components are added to child components in a similar way; multiple components of the same type are supported, as are multiple properties with the same name in a component.

Finally, call the Vcalendar's render() method.

All iCalendar components are immutable.

UIDs

VEVENT, VFREEBUSY, VJOURNAL, and VTODO components require the UID property;since RFC 7985 it can also be set in VCALENDAR. RFC 7985 udates the recommendation on how to construct the value; it deprecates the use of IP addresses and host and domain names due particularly due privacy and security concerns, and recommends use of Universally Unique Identifier (UUID) values as defined in Sections 4.4 and 4.5 of RFC4122.

The library provides a helper method that generates V4 UUIDs.

$vCalendar = (new Vcalendar())
    ->addProperty(Vcalendar::PROPERTY_UID, Vcalendar::uuidv4())
    ->addComponent((new Vevent())
        ->addProperty(Vevent::PROPERTY_UID, Vevent::uuidv4())
    )
;

Non-standard Components

IANA and X- components can be added to the iCalender object (Vcalendar).

Non-standard components must extend Component and define the NAME constant; they must be registered in Vcalendar before use.

use BeastBytes\ICalendar\Component;

class NonStandardComponent extends Component
{
    public const NAME = 'NON-STANDARD-COMPONENT';

    protected const CARDINALITY = [
        // declare cardinality of the component's properties here
    ];
}
---
Vcalendar::registerNonStandardComponent(NonStandardComponent::NAME);

$nonStandardComponent = new NonStandardComponent();

$vCalendar = (new Vcalendar())->addComponent($nonStandardComponent);
// $vCalendar->hasComponent(NonStandardComponent::NAME) === true;

Non-standard Properties

IANA and X- properties can be added to iCalender components.

Non-standard properties must be registered with the component before use; the default cardinality is one or many may be present.

public const NON_STANDARD_PROPERTY = 'NON-STANDARD-PROPERTY';

Vevent::registerNonStandardProperty(self::NON_STANDARD_PROPERTY, Vevent::CARDINALITY_ONE_MAY);

$vEvent = (new Vevent())->addProperty(self::NON_STANDARD_PROPERTY, $value);
// $vEvent->hasProperty(self::NON_STANDARD_PROPERTY) === true;

Example

The following example creates a To-Do with an alarm (it is the example on page 146 of RFC5545 modified to use UUID V4 for UID).

$iCalendar = (new Vcalendar())
    ->addProperty(Vcalendar::PROPERTY_PRODUCT_IDENTIFIER, '-//ABC Corporation//NONSGML My Product//EN')
    ->addComponent((new Vtodo())
        ->addProperty(Vtodo::PROPERTY_DATETIME_STAMP, '19980130T134500Z')
        ->addProperty(Vtodo::PROPERTY_SEQUENCE, 2)
        ->addProperty(Vtodo::PROPERTY_UID, Vtodo::uuidv4())
        ->addProperty(Vtodo::PROPERTY_ORGANIZER, 'mailto:unclesam@example.com')
        ->addProperty(
            Vtodo::PROPERTY_ATTENDEE,
            'mailto:jqpublic@example.com',
            [
                Vtodo::PARAMETER_PARTICIPATION_STATUS => Vtodo::STATUS_ACCEPTED
            ]
        )
        ->addProperty(Vtodo::PROPERTY_DATETIME_DUE, '19980415T000000')
        ->addProperty(Vtodo::PROPERTY_STATUS, Vtodo::STATUS_NEEDS_ACTION)
        ->addProperty(Vtodo::PROPERTY_SUMMARY, 'Submit Income Taxes')
        ->addComponent((new Valarm())
            ->addProperty(Valarm::PROPERTY_ACTION, Valarm::ACTION_AUDIO)
            ->addProperty(Valarm::PROPERTY_TRIGGER, '19980403T120000Z')
            ->addProperty(
                Valarm::PROPERTY_ATTACH,
                'http://example.com/pub/audio-files/ssbanner.aud',
                [
                    Valarm::PARAMETER_FORMAT_TYPE => 'audio/basic'
                ]
            )
            ->addProperty(Valarm::PROPERTY_REPEAT, 4)
            ->addProperty(Valarm::PROPERTY_DURATION, 'PT1H')
        )
    )
    ->render()
;

See tests for more examples.

Edit iCalendar

iCalendar components can be edited, for example when updating a Vevent.

The library has methods for editing components:

  • hasComponent($name) - whether a component has one or more components of type $name

  • getComponents() - returns all child components

  • getComponent($name) - returns all child components of type $name

  • getComponent($name, $n) - returns the $nth occurrence of the child component of type $name

  • setComponent($component, $n) - set (overwrite) the $nth occurrence of the type of $component with $component

  • removeComponent($name) - remove all child components of type $name

  • removeComponent($name, $n) - remove the $nth occurrence of the child component of type $name

  • hasProperty($name) - whether a component has one or more properties of type $name

  • getProperties() - returns all component properties

  • getProperty($name) - returns all component properties of type $name

  • getProperty($name, $n) - returns the $nth occurrence of the component property of type $name

  • setProperty($name, $n, $value, $parameters) - set (overwrite) the $nth occurrence of the property of type $name with new $value and $parameters

  • removeProperty($name) - remove all component properties of type $name

  • removeProperty($name, $n) - remove the $nth occurrence of the component property of type $name

Import iCalendar

Import an iCalendar string using Vcalendar::import():

$icalendar = Vcalendar::import($string);

Installation

The preferred way to install the library is with composer.

Either run

php composer.phar require --prefer-dist beastbytes/icalendar

or add

"beastbytes/icalendar": "*"

to the 'require' section of your composer.json.

Testing

Unit testing

The package is tested with PHPUnit. To run the tests:

./vendor/bin/phpunit

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The iCalendar Library is free software. It is released under the terms of the BSD License. For license information see the LICENSE file.

beastbytes/icalendar 适用场景与选型建议

beastbytes/icalendar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「iCalendar」 「RFC 5545」 「RFC 7986」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 beastbytes/icalendar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 beastbytes/icalendar 我们能提供哪些服务?
定制开发 / 二次开发

基于 beastbytes/icalendar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-02-04