holidayapi/holidayapi-php

假日API的官方PHP库

4.0.0 2023-11-06 18:43 UTC

This package is auto-updated.

Last update: 2024-09-06 20:39:56 UTC


README

License PHP Version Code Coverage

假日API的官方PHP库,为PHP编写的应用程序提供快速便捷地访问假日信息。

文档

假日API端点的完整文档可在此处找到。

安装

composer require holidayapi/holidayapi-php

使用方法

<?php
$key = 'Insert your API key here';
$holiday_api = new \HolidayAPI\Client(['key' => $key]);

try {
    // Fetch supported countries and subdivisions
    $countries = $holiday_api->countries();

    // Fetch supported languages
    $languages = $holiday_api->languages();

    // Fetch holidays with minimum parameters
    $holidays = $holiday_api->holidays([
      'country' => 'US',
      'year' => 2019,
    ]);

    var_dump($countries, $languages, $holidays);
} catch (Exception $e) {
    var_dump($e);
}

示例

国家

获取所有支持的国家

<?php
$holiday_api->countries();

获取有公共假日的国家

<?php
$holiday_api->countries([
  'public' => true,
]);

通过代码获取支持的国家

<?php
$holiday_api->countries([
  'country' => 'NO',
]);

通过代码或名称搜索国家

<?php
$holiday_api->countries([
  'search' => 'united',
]);

语言

获取所有支持的语言

<?php
$holiday_api->languages();

通过代码获取支持的语言

<?php
$holiday_api->languages([
  'language' => 'es',
]);

通过代码或名称搜索语言

<?php
$holiday_api->languages([
  'search' => 'Chinese',
]);

假日

获取特定年份的假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
]);

获取特定月份的假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
]);

获取特定日期的假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
  'day' => 4,
]);

基于特定日期获取即将到来的假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
  'day' => 4,
  'upcoming' => true,
]);

基于特定日期获取过去的假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'month' => 7,
  'day' => 4,
  'previous' => true,
]);

仅获取公共假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'public' => true,
]);

获取特定子区域的假日

<?php
$holiday_api->holidays([
  'country' => 'GB-ENG',
  'year' => 2019,
]);

包含全国假日和子区域假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'subdivisions' => true,
]);

通过名称搜索假日

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'search' => 'New Year',
]);

将假日翻译成另一种语言

<?php
$holiday_api->holidays([
  'country' => 'US',
  'year' => 2019,
  'language' => 'zh', // Chinese (Simplified)
]);

获取多个国家的假日

<?php
$holiday_api->holidays([
  'country' => 'US,GB,NZ',
  'year' => 2019,
]);

$holiday_api->holidays([
  'country' => ['US', 'GB', 'NZ'],
  'year' => 2019,
]);

工作日

获取日期后7个工作日的工作日

<?php
$holiday_api->workday([
  'country' => 'US',
  'start' => '2019-07-01',
  'days' => 7,
]);

工作日

获取两个日期之间的工作日数量

<?php
$holiday_api->workdays([
  'country' => 'US',
  'start' => '2019-07-01',
  'end' => '2019-07-10',
]);