Official PHP library for Holiday API https://holidayapi.com
Find a file
Josh Sherman 0f45ca781a chore(ci): include 7.4 and nightly
* chore(ci): Added 7.4 (just released) and nightly (as an allowed failure).
* chore(composer): Swap out abandoned coveralls package for maintained version.
* chore(composer): Added PHPUnit as a dev dependency.
* chore(ci): Dropped a ton of the juggling in favor of version juggling in Composer.
* fix(readme): Corrected the badge for the license.
* chore(composer): Bumped the package's version number.
2019-12-05 19:32:12 -06:00
src feat: include all endpoints 2019-10-10 00:12:13 -05:00
tests feat: include all endpoints 2019-10-10 00:12:13 -05:00
.coveralls.yml feat: include all endpoints 2019-10-10 00:12:13 -05:00
.gitignore feat: include all endpoints 2019-10-10 00:12:13 -05:00
.travis.yml chore(ci): include 7.4 and nightly 2019-12-05 19:32:12 -06:00
composer.json chore(ci): include 7.4 and nightly 2019-12-05 19:32:12 -06:00
LICENSE feat: include all endpoints 2019-10-10 00:12:13 -05:00
phpunit.xml feat: include all endpoints 2019-10-10 00:12:13 -05:00
README.md chore(ci): include 7.4 and nightly 2019-12-05 19:32:12 -06:00

Holiday API PHP Library

License PHP Version Build Status Coverage Status

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

Migrating from 1.x

Please note, version 2.x of this library is a full rewrite of the 1.x series. The interfacing to the library has been simplified and existing applications upgrading to 2.x will need to be updated.

Version 1.x Syntax (Old) Version 2.x Syntax (New)
$holiday_api = new \HolidayAPI\v1($key); $holiday_api = new \HolidayAPI\Client(['key' => $key]);

Version 1.x of the library can still be found here.

Documentation

Full documentation of the Holiday API endpoints is available here.

Installation

composer require holidayapi/holidayapi-php

Usage

$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

$holiday_api->countries();

Search for a country by code or name

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

Languages

Fetch all supported languages

$holiday_api->languages();

Search for a language by code or name

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

Holidays

Fetch holidays for a specific year

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

Fetch holidays for a specific month

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

Fetch holidays for a specific day

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

Fetch upcoming holidays based on a specific date

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

Fetch previous holidays based on a specific date

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

Fetch only public holidays

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

Fetch holidays for a specific subdivision

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

Include subdivision holidays with countrywide holidays

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

Search for a holiday by name

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

Translate holidays to another language

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

Fetch holidays for multiple countries

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

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