定制 titasgailius/calendar 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

titasgailius/calendar

Composer 安装命令:

composer require titasgailius/calendar

包简介

Calendar is an intuitive abstraction around various calendar providers.

README 文档

README

Calendar

Easily manage Google & Microsoft calendars.

Setup

Before managing events, you need to initialise a Google or Microsoft calendar.

Initializing Google Calendar

To initialise a Google calendar, you need to pass client & user credentials and a callback that is run when an expired access token is refreshed.

$calendar = Calendar::google(
    client: [
        'client_id' => 'GOOGLE_CLIENT_ID',
        'client_secret' => 'GOOGLE_CLIENT_SECRET',
    ],
    token: [
        'refresh_token' => 'USER_REFRESH_TOKEN',
        'access_token' => 'USER_ACCESS_TOKEN',
        'created' => 1679422799,
        'expires_in' => 1679426399,
    ],
    onTokenRefresh: fn (array $token) => var_dump($token),
);

Initializing Microsoft Calendar

To initialise a Microsoft calendar, you may pass user credentials and a callback that is run when an expired access token is refreshed.

$calendar = Calendar::microsoft(
    client: [
        'client_id' => 'MICROSOFT_CLIENT_ID',
        'client_secret' => 'MICROSOFT_CLIENT_SECRET',
    ],
    token: [
        'refresh_token' => 'USER_REFRESH_TOKEN',
        'access_token' => 'USER_ACCESS_TOKEN',
        'created' => 1679422799,
        'expires_in' => 1679426399,
    ],
    onTokenRefresh: fn (array $token) => var_dump($token),
);

Usage

Creating Events

To create a calendar event, simply pass a new Event instance to the createEvent method.

$event = $calendar->createEvent(new Event(
    title: 'My fist event',
    start: Carbon::now()->addMinutes(30),
    end: Carbon::now()->addMinutes(60),
    attendees: ['john.doe@example.com'],
));

Retrieving Events

To retrieve an event, simply pass an id of the event to the getEvent method.

$event = $calendar->getEvent('442d81dvg884c57an0g778e184');

Updating Events

To update an event, simply pass an Event instance to the updateEvent method.

$event->title = 'Updated Event Title';
$calendar->updateEvent($event);

Deleting Events

To delete an event, simply pass an event id to the deleteEvent method.

$calendar->deleteEvent('442d81dvg884c57an0g778e184');

Listing Events

To list events, simply call the getEvents method. The result of this method is an instance of a Paginator object.

$paginator = $calendar->getEvents();

To loop through all event pages, you may call the next method on the Paginator instance.

while ($events = $paginator->next()) {
    //
}

To loop through all events from all pages, you may call the each method on the Paginator instance and pass a callback that is run with each event instance.

$calendar->each(function (Event $event) {
    //
});

To collect all events in memory, you may call the all method on the Paginator instance.

$events = $paginator->all();

Listing Calendars

To list calendars, simply call the getCalendars method. The result of this method is an instance of a Paginator object.

$paginator = $calendar->getCalendars();

To loop through all calendar pages, you may call the next method on the Paginator instance.

while ($calendars = $paginator->next()) {
    //
}

To loop through all calendars from all pages, you may call the each method on the Paginator instance and pass a callback that is run with each calendar instance.

$paginator->each(function (Calendar $calendar) {
    //
});

To collect all calendars in memory, you may call the all method on the Paginator instance.

$calendars = $paginator->all();

Resources

Below, you may find FULL definitions of each calendar resource.

new Event(
    title: 'My First Calendar Event',
    start: now()->addMinutes(30),
    end: now()->addMinutes(60),
    organiser: new Organiser('john@example.com'),
    attendees: [
        new Attendee(email: 'bob@example.com', rsvp: Rsvp::ACCEPTED),
        new Attendee(email: 'rob@example.com', rsvp: Rsvp::PENDING),
    ],
    calendar: 'primary',
    id: '442d81dvg884c57an0g778e184',
);

new Calendar(
    provider: 'google',
    id: '442d81dvg884c57an0g778e184',
    name: 'Public Holidays Calendar',
);

Extending

To add a new provider, simple implement the TitasGailius\Calendar\Contracts\Provider interface for your provider.

interface Provider
{
    /**
     * List calendars.
     *
     * @param  mixed[]  $options
     * @return \TitasGailius\Calendar\Contracts\Paginator<\TitasGailius\Calendar\Resources\Calendar>
     */
    public function getCalendars(array $options = []): Paginator;

    /**
     * List events.
     *
     * @param  mixed[]  $options
     * @return \TitasGailius\Calendar\Contracts\Paginator<\TitasGailius\Calendar\Resources\Event>
     */
    public function getEvents(array $options = []): Paginator;

    /**
     * Create an event.
     *
     * @param  mixed[]  $options
     */
    public function createEvent(Event $event, array $options = []): Event;

    /**
     * Get event.
     *
     * @param  mixed[]  $options
     */
    public function getEvent(string|Event $event, array $options = []): ?Event;

    /**
     * Save a new event.
     *
     * @param  mixed[]  $options
     */
    public function updateEvent(Event $event, array $options = []): Event;

    /**
     * Delete a given event.
     *
     * @param  mixed[]  $options
     */
    public function deleteEvent(string|Event $event, array $options = []): void;
}

then, register your custom Calendar provider

Calendar::extend('calendly', function (array $config = []) {
    return new CalendlyProvider($options);
});

Finally, you may retrieve your custom provider by calling the provider method

$calenar = Calendar::provider('calendly', [
    'token ' => 'CALENDLY_TOKEN',
]);

titasgailius/calendar 适用场景与选型建议

titasgailius/calendar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 392 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-16