midnite81/bank-holidays
Composer 安装命令:
composer require midnite81/bank-holidays
包简介
A library to get UK bank holidays
README 文档
README
This package integrates with the UK Government's Bank Holiday Json response. It has been principally been designed for use with laravel, but is framework agnostic under the hood. This package requires PHP 7.1 or greater.
Installation
composer require midnite81/bank-holidays
If you are using laravel 5.4 or less, you will need to register the Bank Holiday service provider. If you are using 5.5 or greater than the package should be auto discovered.
'providers' => [
...
\Midnite81\BankHolidays\BankHolidayServiceProvider::class,
...
];
You will need to publish the configuration file. To do this, please run
php artisan vendor:publish provider="Midnite81\BankHolidays\BankHolidayServiceProvider"
Limitation
The UK Government provides the bank holiday json feed, this at the time of writing only includes the years between 2015 and 2021.
Versions
| Version | Description |
|---|---|
| v2.0 ✅ | Php 7.1+ |
| v1.0 | Php 5.5.9+ Depreciated |
View changelog for changes.
Http standards
To adhere to better standards, this package uses the popular and powerful PHP-HTTP library to make HTTP requests. This allows you, should you wish, to use your own HTTP Client instead of the default provided with this package. For more information on PHP-HTTP, please visit php-http.org.
Laravel usage example
Checking a date to see if it's a bank holiday
use Midnite81\BankHolidays\Contracts\IBankHoliday; public function myFunction(IBankHoliday $bankHoliday) { $bankHolidayEntity = $bankHoliday->bankHolidayDetail( \Carbon\Carbon::create(2020, 01, 01), \Midnite81\BankHolidays\Enums\Territory::ENGLAND_AND_WALES ); // if the date provided is a bank holiday a BankHolidayEntity is returned // otherwise it returns null. If the entity is returned you can access the entity properties below.
if ($bankHoliday->isBankHoliday(
\Carbon\Carbon::create(2020, 01, 01),
\Midnite81\BankHolidays\Enums\Territory::ENGLAND_AND_WALES
)) {
// if it is a bank holiday do this ...
}
}
Get all bank holiday dates
use Midnite81\BankHolidays\Contracts\IBankHoliday; public function myFunction(IBankHoliday $bankHoliday) { $bankHolidays = $bankHoliday->getAll(\Midnite81\BankHolidays\Enums\Territory::ENGLAND_AND_WALES); foreach($bankHolidays as $bankHoliday) { echo $bankHoliday->title . "<br>\n"; } }
Check data range
The UK government supplies the data which is used in this package and is subject to date range limitations. Due to these limitations, this package provides two methods for you to ascertain the minimum and maximum dates in the data are available for you to check against.
use Midnite81\BankHolidays\Contracts\IBankHoliday; public function myFunction(IBankHoliday $bankHoliday) { $minimumDate = $bankHoliday->getMinDate(\Midnite81\BankHolidays\Enums\Territory::ENGLAND_AND_WALES); $maximumDate = $bankHoliday->getMaxDate(\Midnite81\BankHolidays\Enums\Territory::ENGLAND_AND_WALES); }
Usage without laravel
public function someFunction() { $config = [ 'cache-duration' => 60 * 60 * 24, 'bank-holiday-url' => 'https://www.gov.uk/bank-holidays.json', 'cache-key' => 'midnite81-bank-holidays', 'cache-class' => YourCacheClass::class, // you will need to create a cache class 'filesystem-class' => \Midnite81\BankHolidays\Drivers\PhpFileSystem::class, 'http-client' => null, 'failure-backup' => true, 'request-factory' => null ]; $cache = new YourCacheClass(); // this must implement \Midnite81\BankHolidays\Contracts\Drivers\ICache $client = new \Midnite81\BankHolidays\Services\Client(null, null, $config); $bankHoliday = new \Midnite81\BankHolidays\BankHoliday($client, $cache, $config); // Once you have $bankHoliday instantiated you can use the following methods $bankHoliday->getAll(int $territory); $bankHoliday->bankHolidayDetail(Carbon $date, int $territory); // for territory please use the constants in `Midnite81\BankHolidays\Enums\Territory` }
Bank Holiday Entity
The bank holiday entity has the following properties.
title - the title of the holiday - e.g. New Year's Day
date - a carbon instance of the bank holiday date
notes - any notes about the bank holiday
bunting - presumably whether bunting is displayed
territory - the territory the bank holiday applies to
Territories
The following territories are available
Midnite81\BankHolidays\Enums\Territory::ENGLAND_AND_WALES; // England and Wales Midnite81\BankHolidays\Enums\Territory::SCOTLAND; // Scotland Midnite81\BankHolidays\Enums\Territory::NORTHERN_IRELAND; // Northern Ireland Midnite81\BankHolidays\Enums\Territory::ALL; // All territories (e.g. England, Wales, Scotland and Northern Ireland)
midnite81/bank-holidays 适用场景与选型建议
midnite81/bank-holidays 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.36k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 midnite81/bank-holidays 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 midnite81/bank-holidays 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-18