acrnogor/ical-exporter

v0.7.4 2018-03-23 13:19 UTC

This package is auto-updated.

Last update: 2024-09-25 23:20:27 UTC


README

需要Twig模板引擎来渲染ICS文件。

安装

composer require acrnogor/ical-exporter

使用方法

// first, we need Twig environement
$loader = new Twig_Loader_Filesystem();
$twig   = new Twig_Environment($loader, [
    'cache' => __DIR__ . '/var/cache',
]);

// now create new ICalExporter object and download event items as ICS file
$filename = 'this-is-my-calendar.ics';
$icalExporter = new ICalExporter($twig);
$ice->downloadAsICal($items, $filename);

或者,如果您只想获取ICS正文作为字符串/文本

// you an either repeat Twig part or just use Dependency Injection (i.e. in Symfony) to inject twig to the class, then fetch it as a service
...

// now create new ICalExporter object and download event items as ICS file
$icalExporter = new ICalExporter($twig);
$icsText = $ice->getICalDataAsString($items);
echo $icsText;

Symfony 3.0+ 使用方法

通过composer安装将ICalExporter添加到您的Symfony项目中。然后,在services.yml中定义一个Symfony服务

ical_exporter:
    class: Acrnogor\ICalExporter\ICalExporter
    arguments: ["@twig"]

然后在config.yml中配置twig模板路径

twig:
    paths:
        '%kernel.root_dir%/../vendor/acrnogor/ical-exporter/src/View/': ~

然后您可以在控制器中使用此服务,如下所示

$icalExporter = $this->get('ical_exporter');
$icalExporter->downloadAsICal($events, 'give-some-filename.ics');

待办事项

  • 可能实现一个非Twig版本?嗯...

在Packagist上

https://packagist.org.cn/packages/acrnogor/ical-exporter