openactive/dataset-site

用于渲染 OpenActive 数据集网站的库

安装次数: 160,876

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 10

分支: 3

开放问题: 3

语言:Mustache

类型:项目

v7.0.0 2022-07-20 16:01 UTC

This package is auto-updated.

Last update: 2024-09-03 19:25:26 UTC


README

PHP 类和资源,支持创建数据集网站,例如 这个示例(或列表中的其他示例这里)。

此包旨在通过模板简化创建 OpenActive 数据集网站

比较而言,请参阅 .NETRuby 实现。

有关创建配套 GitHub 问题板的完整文档,请参阅 https://developer.openactive.io/publishing-data/dataset-sites

目录

要求

此项目需要 PHP >=5.6。虽然大多数功能应该可以向下兼容到 PHP 5.4,但某些功能(尤其是在 DateTimeZone 的偏移量解析方面)将无法使用该版本的 PHP(有关更多信息,请参阅 DateTimeZone PHP 文档)。

还需要 Composer 来进行依赖关系管理。

此项目还使用 Mustache 来渲染模板(通过 Composer 安装)。

用法

请注意:这些说明是临时的,并基于当前的开发状态。

如果您正在开发此包,请参阅 贡献 部分。

要从终端安装,请运行

composer require openactive/dataset-site

在您想要渲染数据集页面的任何位置,包括以下说明

use OpenActive\DatasetSiteTemplate\TemplateRenderer;

// Render compiled template with data
echo (new TemplateRenderer())->renderSimpleDatasetSite($settings, $supportedFeedTypes);

或要渲染一个 CSP 兼容的模板,首先确保您正在通过此版本的 PHP 包的 URL 提供此版本的 CSP 兼容的静态资产,然后包括以下内容

use OpenActive\DatasetSiteTemplate\TemplateRenderer;

// Render compiled template with data
echo (new TemplateRenderer())->renderSimpleDatasetSite($settings, $supportedFeedTypes, $staticAssetsPathUrl);

其中 $settings 可以定义如下(例如)

$settings = array(
    "openDataFeedBaseUrl" => "https://customer.example.com/feed/",
    "datasetSiteUrl" => "https://halo-odi.legendonlineservices.co.uk/openactive/",
    "datasetDiscussionUrl" => "https://github.com/gll-better/opendata",
    "datasetDocumentationUrl" => "https://docs.acmebooker.example.com/",
    "datasetLanguages" => array("en-GB"),
    "organisationName" => "Better",
    "organisationUrl" => "https://www.better.org.uk/",
    "organisationLegalEntity" => "GLL",
    "organisationPlainTextDescription" => "Established in 1993, GLL is the largest UK-based charitable social enterprise delivering leisure, health and community services. Under the consumer facing brand Better, we operate 258 public Sports and Leisure facilities, 88 libraries, 10 children’s centres and 5 adventure playgrounds in partnership with 50 local councils, public agencies and sporting organisations. Better leisure facilities enjoy 46 million visitors a year and have more than 650,000 members.",
    "organisationLogoUrl" => "http://data.better.org.uk/images/logo.png",
    "organisationEmail" => "info@better.org.uk",
    "platformName" => "AcmeBooker",
    "platformUrl" => "https://acmebooker.example.com/",
    "platformSoftwareVersion" => "2.0",
    "backgroundImageUrl" => "https://data.better.org.uk/images/bg.jpg",
    "dateFirstPublished" => "2019-10-28",
    "openBookingAPIBaseUrl" => "https://reference-implementation.openactive.io/api/openbooking",
    "openBookingAPIAuthenticationAuthorityUrl" => "https://auth.reference-implementation.openactive.io",
    "openBookingAPIDocumentationUrl" => "https://permalink.openactive.io/dataset-site/open-booking-api-documentation",
    "openBookingAPITermsOfServiceUrl" => "https://example.com/api-terms-page",
    "openBookingAPIRegistrationUrl" => "https://example.com/api-landing-page",
    "testSuiteCertificateUrl" => "https://certificates.reference-implementation.openactive.io/examples/all-features/controlled/",
);

$supportedFeedTypes 可以定义为

use OpenActive\DatasetSiteTemplate\FeedType;

$supportedFeedTypes = array(
    FeedType::FACILITY_USE,
    FeedType::SCHEDULED_SESSION,
    FeedType::SESSION_SERIES,
    FeedType::SLOT,
);

如果需要,$staticAssetsPathUrl 应设置为包含 CSP 静态资产文件的目录的 URL 路径(使用此版本的 PHP 包中的资产存档,使用此版本的 PHP 包中的资产存档)。

API

renderSimpleDatasetSite($settings, $supportedFeedTypes, $staticAssetsPathUrl = null)

返回一个基于 datasetsite.mustache、提供的 $settings$supportedFeedTypes 编译的 HTML 字符串。

如果提供了$staticAssetsPathUrl,则会渲染与CSP兼容的模板。[查看更多](https://developer.openactive.io/publishing-data/dataset-sites#template-hosting-options "CSP兼容的模板")。在这种情况下,您必须确保在这个位置提供CSP兼容的静态资产存档[查看更多](https://github.com/openactive/dataset-site-template-php/blob/HEAD//src/datasetsite-csp.static.zip "CSP兼容的静态资产存档"),使用这个PHP版本包中的资产存档。

$settings必须包含以下键

设置

并且$supportedFeedTypes必须是一个包含FeedType常量的array,这将使用最佳实践值自动生成与每个数据源相关的元数据。查看[可用类型](#user-content-feedtype)

renderSimpleDatasetSiteFromDataDownloads($settings, $dataDownloads, $dataFeedDescriptions, $staticAssetsPathUrl = null)

返回一个与编译后的HTML相对应的字符串,基于datasetsite.mustache、提供的$settings$dataDownloads$dataFeedDescriptions

如果提供了$staticAssetsPathUrl,则会渲染与CSP兼容的模板。[查看更多](https://developer.openactive.io/publishing-data/dataset-sites#template-hosting-options "CSP兼容的模板")。在这种情况下,您必须确保在这个位置提供CSP兼容的静态资产存档[查看更多](https://github.com/openactive/dataset-site-template-php/blob/HEAD//src/datasetsite-csp.static.zip "CSP兼容的静态资产存档"),使用这个PHP版本包中的资产存档。

$dataDownloads参数必须是一个包含\OpenActive\Models\OA\DataDownload对象的array,每个对象描述一个可用的开放数据源。

$dataFeedDescriptions必须是一个字符串数组,描述数据集,例如

$dataFeedDescriptions = array(
    "Sessions",
    "Facilities"
);

renderDatasetSite($dataset, $staticAssetsPathUrl = null)

返回一个与编译后的HTML相对应的字符串,基于datasetsite.mustache和提供的$dataset

如果提供了$staticAssetsPathUrl,则会渲染与CSP兼容的模板。[查看更多](https://developer.openactive.io/publishing-data/dataset-sites#template-hosting-options "CSP兼容的模板")。在这种情况下,您必须确保在这个位置提供CSP兼容的静态资产存档[查看更多](https://github.com/openactive/dataset-site-template-php/blob/HEAD//src/datasetsite-csp.static.zip "CSP兼容的静态资产存档"),使用这个PHP版本包中的资产存档。

$dataset参数必须是一个类型为\OpenActive\Models\OA\Dataset的对象,并且必须包含渲染数据集站点所需的属性。

FeedType

包含支持的分发类型的类

您可以使用以下方式使用上述任何一种

use OpenActive\DatasetSiteTemplate\FeedType;

echo FeedType::COURSE_INSTANCE;

这将输出

CourseInstance

贡献

安装

git clone https://github.com/openactive/dataset-site-template-php.git
cd dataset-site-template-php
composer install

示例

要使用PHP内置服务器运行示例

composer start

composer start-csp

运行后,在浏览器中导航到localhost:8080以查看填充了JSON-LD数据的模板。

默认的mustache模板(datasetsite.mustachedatasetsite-csp.mustache)位于src文件夹中。

index.php中,您可以找到由TemplateRenderer解析的关联数组的示例。

运行测试

使用PHPUnit运行测试。

要运行整个套件

composer test

如果您想以详细模式运行整个套件

composer test -- --verbose

您还可以通过指定要对其执行测试的类的相对路径来运行套件的某个部分

composer test -- --verbose tests/Unit/TemplateRendererTest.php

有关PHPUnit可用的命令的更多信息,请参阅他们的文档

发布

此库的主要版本号应与所依赖的dataset-site-template的主要版本号相匹配。对数据集站点模板文件或资产的任何更新都应在这两个库中始终是一个主要版本更新。