san103/php-holiday-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

san103/php-holiday-api

最新稳定版本:v1.3.9

Composer 安装命令:

composer require san103/php-holiday-api

包简介

An holiday API for php

README 文档

README

A Dynamic Holiday package for Php/ Laravel based on Google Calendar API

composer require san103/php-holiday-api

Prerequisites

  • PHP 8.0 or higher
  • Composer
  • Guzzlehttp/guzzle"

Installation

composer install
composer require guzzlehttp/guzzle:^7.0

Basic Usage

Define package

namespace App/YourApp

use San103\Phpholidayapi\HolidayClient;
$holiday = new HolidayClient();
  • (Optional) Set your Country Code e.g uk for United Kindom, us for United State default sets to Philippines
countryCode('uk')
  • (Optional) Set Year you want to display the holiday dates , default is set to current year which is 2023
year('2022')

Important

The result() must define in last chain.

result(); 
  • Example usage in php
require 'vendor/autoload.php';
use San103\Phpholidayapi\HolidayClient;

public function index(){

        $api = new HolidayClient();
        return $api
                    ->countryCode('uk') 
                    ->year('2023') 
                    ->result();
      
    }
  • Example usage in Laravel 10
use San103\Phpholidayapi\HolidayClientLaravel;

public function index(){

        $api = new HolidayClientLaravel();
        return $api
                    ->countryCode('uk') 
                    ->year('2023') 
                    ->result();
      
    }

Special Feature for Laravel 10

  • Install Cache
  • use the HolidayClientLaravel source
 return Cache::remember(date('Y'), now()->addMonth(), function () use ($http) {

change the now()->addMonth() to set expiration of the cache

Note

You may also provide your own Api key from Google API. just enable the Calendar Api and generate key

apiKey('your-api-key')

Output

"
{
    "21":{
        "id":"20230101_i536",
        "title":"New Year\'s Day",
        "description":"Public holiday",
        "date":{"date":"2023-01-01"}},

    "23":{
        "id":"20230225_qh5n",
        "title":"People Power Anniversary",
        "description":"Public holiday",
        "date":{"date":"2023-02-25"}},

    "24":{
        "id":"20230406_hvi",
        "title":"Maundy Thursday",
        "description":"Public holiday",
        "date":{"date":"2023-04-06"}},

    "25":{
        "id":"20230407_fv",
        "title":"Good Friday",
        "description":"Public holiday",
        "date":{"date":"2023-04-07"}},

    "26":{
        "id":"20230408_6v",
        "title":"Black Saturday",
        "description":"Public holiday",
        "date":{"date":"2023-04-08"}},

    "28":{
        "id":"20230501_on",
        "title":"Labor Day",
        "description":"Public holiday",
        "date":{"date":"2023-05-01"}},

    "29":{
        "id":"20230612_kq",
        "title":"Independence Day",
        "description":"Public holiday",
        "date":{"date":"2023-06-12"}},

    "30":{
        "id":"20230821_p0c",
        "title":"Ninoy Aquino Day",
        "description":"Public holiday",
        "date":{"date":"2023-08-21"}},
    ...
"

Important

If you make this useful give us a star! Thank you and GodBless

License

The package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 304
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-07