Official PHP library for Holiday API https://holidayapi.com
Find a file
Josh Sherman 15052790c5 feat: get previous workday
Added the ability to get the previous workday by passing in a negative
number of days along with the date to start from.

This update also includes some overhauling to allow for the library to
be more resilient to changes in the upstream API.
2022-04-05 18:02:30 -05:00
.github/workflows feat: get previous workday 2022-04-05 18:02:30 -05:00
src feat: get previous workday 2022-04-05 18:02:30 -05:00
tests feat: get previous workday 2022-04-05 18:02:30 -05:00
.gitignore feat: include all endpoints 2019-10-10 00:12:13 -05:00
codecov.yml build: swap travis for github actions 2020-06-13 10:19:15 -05:00
composer.json feat: get previous workday 2022-04-05 18:02:30 -05:00
LICENSE feat: get previous workday 2022-04-05 18:02:30 -05:00
phpunit.xml Add assertRegExp assertion checking 2021-06-10 23:01:28 -05:00
README.md feat: add workdays endpoint 2021-06-14 18:01:47 -05:00

Holiday API PHP Library

License PHP Version Test Status Code Coverage

Official PHP library for Holiday API providing quick and easy access to holiday information from applications written in PHP.

Documentation

Full documentation of the Holiday API endpoints is available here.

Installation

composer require holidayapi/holidayapi-php

Usage

<?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);
}

Examples

Countries

Fetch all supported countries

<?php
$holiday_api->countries();

Fetch only countries with public holidays

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

Fetch a supported country by code

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

Search for countries by code or name

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

Languages

Fetch all supported languages

<?php
$holiday_api->languages();

Fetch a supported language by code

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

Search for languages by code or name

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

Holidays

Fetch holidays for a specific year

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

Fetch holidays for a specific month

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

Fetch holidays for a specific day

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

Fetch upcoming holidays based on a specific date

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

Fetch previous holidays based on a specific date

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

Fetch only public holidays

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

Fetch holidays for a specific subdivision

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

Include subdivision holidays with countrywide holidays

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

Search for a holiday by name

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

Translate holidays to another language

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

Fetch holidays for multiple countries

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

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

Workday

Fetch workday 7 business days after a date

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

Workdays

Fetch number of workdays between two dates

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