mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 03:01:32 +00:00
resolved conflicts
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"description": "An API extension for DateTime that supports 281 different languages.",
|
||||
"license": "MIT",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"date",
|
||||
"time",
|
||||
"DateTime"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Brian Nesbitt",
|
||||
"email": "brian@nesbot.com",
|
||||
"homepage": "https://markido.com"
|
||||
},
|
||||
{
|
||||
"name": "kylekatarnls",
|
||||
"homepage": "https://github.com/kylekatarnls"
|
||||
}
|
||||
],
|
||||
"homepage": "https://carbon.nesbot.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/briannesbitt/Carbon/issues",
|
||||
"source": "https://github.com/briannesbitt/Carbon",
|
||||
"docs": "https://carbon.nesbot.com/docs"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sponsors/kylekatarnls",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme",
|
||||
"type": "tidelift"
|
||||
},
|
||||
{
|
||||
"url": "https://opencollective.com/Carbon#sponsor",
|
||||
"type": "opencollective"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.8 || ^8.0",
|
||||
"ext-json": "*",
|
||||
"carbonphp/carbon-doctrine-types": "*",
|
||||
"psr/clock": "^1.0",
|
||||
"symfony/polyfill-mbstring": "^1.0",
|
||||
"symfony/polyfill-php80": "^1.16",
|
||||
"symfony/translation": "^3.4 || ^4.0 || ^5.0 || ^6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/dbal": "^2.0 || ^3.1.4 || ^4.0",
|
||||
"doctrine/orm": "^2.7 || ^3.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.0",
|
||||
"kylekatarnls/multi-tester": "^2.0",
|
||||
"ondrejmirtes/better-reflection": "<6",
|
||||
"phpmd/phpmd": "^2.9",
|
||||
"phpstan/extension-installer": "^1.0",
|
||||
"phpstan/phpstan": "^0.12.99 || ^1.7.14",
|
||||
"phpunit/php-file-iterator": "^2.0.5 || ^3.0.6",
|
||||
"phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20",
|
||||
"squizlabs/php_codesniffer": "^3.4"
|
||||
},
|
||||
"provide": {
|
||||
"psr/clock-implementation": "1.0"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Carbon\\": "src/Carbon/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
},
|
||||
"files": [
|
||||
"tests/Laravel/ServiceProvider.php"
|
||||
]
|
||||
},
|
||||
"bin": [
|
||||
"bin/carbon"
|
||||
],
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"phpstan/extension-installer": true,
|
||||
"composer/package-versions-deprecated": true
|
||||
},
|
||||
"process-timeout": 0,
|
||||
"sort-packages": true
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.x-dev",
|
||||
"dev-2.x": "2.x-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Carbon\\Laravel\\ServiceProvider"
|
||||
]
|
||||
},
|
||||
"phpstan": {
|
||||
"includes": [
|
||||
"extension.neon"
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"phpcs": "php-cs-fixer fix -v --diff --dry-run",
|
||||
"phpdoc": "php phpdoc.php",
|
||||
"phpmd": "phpmd src text /phpmd.xml",
|
||||
"phpmd-test": "phpmd tests text /tests/phpmd-test.xml",
|
||||
"phpstan": "phpstan analyse --configuration phpstan.neon",
|
||||
"phpunit": "phpunit --verbose",
|
||||
"style-check": [
|
||||
"@phpcs",
|
||||
"@phpstan",
|
||||
"@phpmd"
|
||||
],
|
||||
"test": [
|
||||
"@phpunit",
|
||||
"@style-check"
|
||||
],
|
||||
"sponsors": "php sponsors.php"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
# Carbon
|
||||
|
||||
[](https://packagist.org/packages/nesbot/carbon)
|
||||
[](https://packagist.org/packages/nesbot/carbon)
|
||||
[](https://github.com/briannesbitt/Carbon/actions)
|
||||
[](https://codecov.io/github/briannesbitt/Carbon?branch=master)
|
||||
[](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme)
|
||||
|
||||
An international PHP extension for DateTime. [https://carbon.nesbot.com](https://carbon.nesbot.com)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
printf("Right now is %s", Carbon::now()->toDateTimeString());
|
||||
printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver')); //implicit __toString()
|
||||
$tomorrow = Carbon::now()->addDay();
|
||||
$lastWeek = Carbon::now()->subWeek();
|
||||
$nextSummerOlympics = Carbon::createFromDate(2016)->addYears(4);
|
||||
|
||||
$officialDate = Carbon::now()->toRfc2822String();
|
||||
|
||||
$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;
|
||||
|
||||
$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');
|
||||
|
||||
$internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT');
|
||||
|
||||
// Don't really want this to happen so mock now
|
||||
Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
|
||||
|
||||
// comparisons are always done in UTC
|
||||
if (Carbon::now()->gte($internetWillBlowUpOn)) {
|
||||
die();
|
||||
}
|
||||
|
||||
// Phew! Return to normal behaviour
|
||||
Carbon::setTestNow();
|
||||
|
||||
if (Carbon::now()->isWeekend()) {
|
||||
echo 'Party!';
|
||||
}
|
||||
// Over 200 languages (and over 500 regional variants) supported:
|
||||
echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
|
||||
echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前'
|
||||
echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM'
|
||||
echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51'
|
||||
|
||||
// ... but also does 'from now', 'after' and 'before'
|
||||
// rolling up to seconds, minutes, hours, days, months, years
|
||||
|
||||
$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
|
||||
```
|
||||
|
||||
[Get supported nesbot/carbon with the Tidelift Subscription](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme)
|
||||
|
||||
## Installation
|
||||
|
||||
### With Composer
|
||||
|
||||
```
|
||||
$ composer require nesbot/carbon
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"nesbot/carbon": "^2.16"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```php
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
printf("Now: %s", Carbon::now());
|
||||
```
|
||||
|
||||
### Without Composer
|
||||
|
||||
Why are you not using [composer](https://getcomposer.org/)? Download the Carbon [latest release](https://github.com/briannesbitt/Carbon/releases) and put the contents of the ZIP archive into a directory in your project. Then require the file `autoload.php` to get all classes and dependencies loaded on need.
|
||||
|
||||
```php
|
||||
<?php
|
||||
require 'path-to-Carbon-directory/autoload.php';
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
printf("Now: %s", Carbon::now());
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
||||
[https://carbon.nesbot.com/docs](https://carbon.nesbot.com/docs)
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the
|
||||
[Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
## Credits
|
||||
|
||||
### Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
|
||||
<a href="https://github.com/briannesbitt/Carbon/graphs/contributors" target="_blank"><img src="https://opencollective.com/Carbon/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
### Translators
|
||||
|
||||
[Thanks to people helping us to translate Carbon in so many languages](https://carbon.nesbot.com/contribute/translators/)
|
||||
|
||||
### Sponsors
|
||||
|
||||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
|
||||
|
||||
<a href="https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme" target="_blank"><img src="https://carbon.nesbot.com/tidelift-brand.png" width="256" height="64"></a><!-- <open-collective-sponsors> -->
|
||||
<a title="Онлайн казино 777 Україна" href="https://777.ua/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Онлайн казино" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/7e572d50-1ce8-4d69-ae12-86cc80371373/ok-ua-777.png" width="64" height="64"></a>
|
||||
<a title="#1 Guide To Online Gambling In Canada" href="https://casinohex.org/canada/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="CasinoHex Canada" src="https://opencollective-production.s3.us-west-1.amazonaws.com/79fdbcc0-a997-11eb-abbc-25e48b63c6dc.jpg" width="85" height="64"></a>
|
||||
<a title="Znajdź najlepsze zakłady bukmacherskie w Polsce w 2023 roku. Probukmacher.pl to Twoje kompendium wiedzy na temat bukmacherów!" href="https://www.probukmacher.pl?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Probukmacher" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/caf50271-4560-4ffe-a434-ea15239168db/Screenshot_1.png" width="89" height="64"></a>
|
||||
<a title="Casino-portugal.pt" href="https://casino-portugal.pt/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Casino-portugal.pt" src="https://logo.clearbit.com/casino-portugal.pt" width="64" height="64"></a>
|
||||
<a title="Gives a fun for our users" href="https://slotoking.ua/games/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Игровые автоматы" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/94601d07-3205-4c60-9c2d-9b8194dbefb7/skg-blue.png" width="64" height="64"></a>
|
||||
<a title="Slots City® ➢ Лучшее лицензионно казино онлайн и оффлайн на гривны в Украине. 【 Более1500 игровых автоматов и слотов】✅ Официально и Безопасно" href="https://slotscity.ua/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Slots City" src="https://opencollective-production.s3.us-west-1.amazonaws.com/d7e298c0-7abe-11ed-8553-230872f5e54d.png" width="90" height="64"></a>
|
||||
<a title="inkedin" href="https://inkedin.com?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="inkedin" src="https://logo.clearbit.com/inkedin.com" width="64" height="64"></a>
|
||||
<a title="Актуальний та повносправний рейтинг онлайн казино України, ґрунтований на відгуках реальних гравців." href="https://uk.onlinecasino.in.ua/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Онлайн казино України" src="https://opencollective-production.s3.us-west-1.amazonaws.com/c0b4b090-eef8-11ec-9cb7-0527a205b226.png" width="64" height="64"></a>
|
||||
<a title="OnlineCasinosSpelen" href="https://onlinecasinosspelen.com?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="OnlineCasinosSpelen" src="https://logo.clearbit.com/onlinecasinosspelen.com" width="64" height="64"></a>
|
||||
<a title="Best non Gamstop sites in the UK" href="https://nongamstopcasinos.net/gb/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Best non Gamstop sites in the UK" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/34e340b8-e1de-4932-8a76-1b3ce2ec7ee8/logo_white%20bg%20(8).png" width="64" height="64"></a>
|
||||
<a title="Real Money Pokies" href="https://www.nzfirst.org.nz/real-money-pokies/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Real Money Pokies" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/30d38232-a9d6-4e95-a48c-641fdc4d96fd/NZ_logo%20(6)%20(1)%20(1).jpg" width="64" height="64"></a>
|
||||
<a title="Non GamStop Bookies UK" href="https://nongamstopbookies.com/uk/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Non GamStop Bookies UK" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/43c5561c-8907-4ef7-a4ee-c6da054788b8/logo-site%20(3).jpg" width="64" height="64"></a>
|
||||
<a title="Актуальний топ-рейтинг українських онлайн казино на гривні! Щоденне оновлення топу та унікальна система ранжування, основана на відгуках гравців!" href="https://onlinecasino.in.ua/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Онлайн Казино Украины" src="https://opencollective-production.s3.us-west-1.amazonaws.com/8fdd8aa0-e273-11ec-a95e-d38fd331cabf.png" width="64" height="64"></a>
|
||||
<a title="Twitter Video Downloader HD Tool allows you to store tweets on your device (mobile or PC) for free." href="https://ssstwitter.online/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="SSSTwitter" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/ba0d1daf-a894-4d98-95f7-a44d321364b3/Screenshot%202024-01-16%20at%2011.43.22.png" width="76" height="64"></a>
|
||||
<a title="Entertainment" href="https://www.nongamstopbets.com/casinos-not-on-gamstop/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Non-GamStop Bets UK" src="https://logo.clearbit.com/nongamstopbets.com" width="64" height="64"></a>
|
||||
<a title="Chudovo - international software development company with representative offices in Kyiv, Cologne, New York, Tallinn and London. It has been working on the market since 2006. Company has domain expertise in video security, logistics, medicine, finance and" href="https://chudovo.com/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Chudovo" src="https://opencollective-production.s3.us-west-1.amazonaws.com/326c19a0-2e87-11eb-a13a-c99a2a201d11.png" width="84" height="42"></a>
|
||||
<a title="Entertainment" href="https://casinogap.org/uk/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="UK Casino Gap" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/143f9301-beec-4118-89d5-9a07a01345f3/casinogap-uk.png" width="42" height="42"></a>
|
||||
<a title="NZ Gaming Portal" href="https://casinodeps.co.nz?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="NZ Casino Deps" src="https://logo.clearbit.com/casinodeps.co.nz" width="42" height="42"></a>
|
||||
<a title="NonStop Sites" href="https://uk.nonstopcasino.org/non-gamstop-casinos/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="NonStopCasino.org" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/fd7ad905-8752-468f-ad20-582a24cca9d9/non-stop-casino.png" width="42" height="42"></a>
|
||||
<a title="Siti Non AAMS" href="https://www.outlookindia.com/outlook-spotlight/migliori-siti-non-aams-siti-scommesse-senza-licenza-sicuri-news-294715?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Migliori Siti Non AAMS" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/392810da-6cb6-4938-a3cb-38bd0e1eb7de/migliori-siti-non-aams.png" width="42" height="42"></a>
|
||||
<a title="List of trusted non GamStop casino reviews" href="https://nongamstopcasinos.org?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="UK NonGamStopCasinos" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/cbda0ee1-26ea-4252-9580-f1f9b317b1f7/nongamstopcasinos-uk.png" width="42" height="42"></a>
|
||||
<a title="Online TikTok Video Download Tool" href="https://snaptik.pro?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="SnapTik" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/546bcd53-6615-457d-ab21-1db1c52b3af5/logo.jpg" width="42" height="42"></a>
|
||||
<a title="Proxidize is a mobile proxy creation and management platform that provides all needed components from hardware to cloud software and SIM cards." href="https://proxidize.com/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Proxidize" src="https://logo.clearbit.com/proxidize.com" width="42" height="42"></a>
|
||||
<a title="IG Downloader is an Instagram Downloader service that offers a variety of tools to download Instagram content for free. Listed below are all the tools" href="https://indownloader.app/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="IG Downloader" src="https://logo.clearbit.com/indownloader.app" width="42" height="42"></a>
|
||||
<a title="Buy Instagram Likes - Real Likes & Instant Delivery!" href="https://blastup.com/buy-instagram-likes?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Blastup" src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/955a0beb-9fe8-4753-ad92-fae8ef5382fc/favicon--dark.jpg" width="42" height="42"></a>
|
||||
<a title="We will boost your Social Media Likes, Followers , Comments & Views. 24/7 hour support. Privacy Assured." href="https://organicsocialboost.com/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Organic Social Boost" src="https://logo.clearbit.com/organicsocialboost.com" width="84" height="42"></a>
|
||||
<a title="A self-hosted web radio management suite, including turnkey installer tools and an easy-to-use web app to manage your stations." href="https://azuracast.com/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="AzuraCast" src="https://opencollective-production.s3.us-west-1.amazonaws.com/3c12ea10-cdfb-11eb-9cf4-3760b386b76d.png" width="42" height="42"></a>
|
||||
<a title="Triplebyte is the first software engineering job platform that is on the developer's side. Take our coding quiz!" href="https://triplebyte.com/os/opencollective?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Triplebyte" src="https://opencollective-production.s3.us-west-1.amazonaws.com/43e4f9d0-30cd-11ea-9c6b-e1142996e8b2.png" width="42" height="42"></a>
|
||||
<a title="Connect your Collective to GitHub Sponsors: https://docs.opencollective.com/help/collectives/github-sponsors" href="https://github.com/sponsors/?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="GitHub Sponsors" src="https://opencollective-production.s3.us-west-1.amazonaws.com/87b1d240-f617-11ea-9960-fd7e8ab20fe4.png" width="48" height="42"></a>
|
||||
<a title="Salesforce" href="https://engineering.salesforce.com?utm_source=opencollective&utm_medium=github&utm_campaign=Carbon" target="_blank"><img alt="Salesforce" src="https://opencollective-production.s3.us-west-1.amazonaws.com/24d34880-df8d-11e9-949c-6bc2037b6bd5.png" width="42" height="42"></a>
|
||||
<!-- </open-collective-sponsors> -->
|
||||
|
||||
[[Become a sponsor via OpenCollective](https://opencollective.com/Carbon#sponsor)]
|
||||
|
||||
<a href="https://github.com/johnrsimeone" target="_blank"><img src="https://avatars.githubusercontent.com/u/22871068?s=70&v=4" width="64" height="64"></a>
|
||||
<a href="https://github.com/taylorotwell" target="_blank"><img src="https://avatars.githubusercontent.com/u/463230?s=128&v=4" width="64" height="64"></a>
|
||||
<a href="https://github.com/getsentry" target="_blank"><img src="https://avatars.githubusercontent.com/u/1396951?s=128&v=4" width="64" height="64"></a>
|
||||
<a href="https://github.com/codecov" target="_blank"><img src="https://avatars.githubusercontent.com/u/8226205?s=128&v=4" width="64" height="64"></a>
|
||||
|
||||
[[Become a sponsor via GitHub](https://github.com/sponsors/kylekatarnls)]
|
||||
|
||||
### Backers
|
||||
|
||||
Thank you to all our backers! 🙏
|
||||
|
||||
<a href="https://opencollective.com/Carbon#backers" target="_blank"><img src="https://opencollective.com/Carbon/backers.svg?width=890&version=2023-06-08-07-12"></a>
|
||||
|
||||
[[Become a backer](https://opencollective.com/Carbon#backer)]
|
||||
|
||||
## Carbon for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of ``Carbon`` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Carbon package.
|
||||
*
|
||||
* (c) Brian Nesbitt <brian@nesbot.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Carbon;
|
||||
|
||||
use Carbon\MessageFormatter\MessageFormatterMapper;
|
||||
use Closure;
|
||||
use ReflectionException;
|
||||
use ReflectionFunction;
|
||||
use Symfony\Component\Translation;
|
||||
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;
|
||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||
|
||||
abstract class AbstractTranslator extends Translation\Translator
|
||||
{
|
||||
/**
|
||||
* Translator singletons for each language.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $singletons = [];
|
||||
|
||||
/**
|
||||
* List of custom localized messages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $messages = [];
|
||||
|
||||
/**
|
||||
* List of custom directories that contain translation files.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $directories = [];
|
||||
|
||||
/**
|
||||
* Set to true while constructing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $initializing = false;
|
||||
|
||||
/**
|
||||
* List of locales aliases.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'me' => 'sr_Latn_ME',
|
||||
'scr' => 'sh',
|
||||
];
|
||||
|
||||
/**
|
||||
* Return a singleton instance of Translator.
|
||||
*
|
||||
* @param string|null $locale optional initial locale ("en" - english by default)
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function get($locale = null)
|
||||
{
|
||||
$locale = $locale ?: 'en';
|
||||
$key = static::class === Translator::class ? $locale : static::class.'|'.$locale;
|
||||
|
||||
if (!isset(static::$singletons[$key])) {
|
||||
static::$singletons[$key] = new static($locale);
|
||||
}
|
||||
|
||||
return static::$singletons[$key];
|
||||
}
|
||||
|
||||
public function __construct($locale, MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false)
|
||||
{
|
||||
parent::setLocale($locale);
|
||||
$this->initializing = true;
|
||||
$this->directories = [__DIR__.'/Lang'];
|
||||
$this->addLoader('array', new ArrayLoader());
|
||||
parent::__construct($locale, new MessageFormatterMapper($formatter), $cacheDir, $debug);
|
||||
$this->initializing = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of directories translation files are searched in.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDirectories(): array
|
||||
{
|
||||
return $this->directories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set list of directories translation files are searched in.
|
||||
*
|
||||
* @param array $directories new directories list
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDirectories(array $directories)
|
||||
{
|
||||
$this->directories = $directories;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a directory to the list translation files are searched in.
|
||||
*
|
||||
* @param string $directory new directory
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDirectory(string $directory)
|
||||
{
|
||||
$this->directories[] = $directory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a directory from the list translation files are searched in.
|
||||
*
|
||||
* @param string $directory directory path
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeDirectory(string $directory)
|
||||
{
|
||||
$search = rtrim(strtr($directory, '\\', '/'), '/');
|
||||
|
||||
return $this->setDirectories(array_filter($this->getDirectories(), function ($item) use ($search) {
|
||||
return rtrim(strtr($item, '\\', '/'), '/') !== $search;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset messages of a locale (all locale if no locale passed).
|
||||
* Remove custom messages and reload initial messages from matching
|
||||
* file in Lang directory.
|
||||
*
|
||||
* @param string|null $locale
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetMessages($locale = null)
|
||||
{
|
||||
if ($locale === null) {
|
||||
$this->messages = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->assertValidLocale($locale);
|
||||
|
||||
foreach ($this->getDirectories() as $directory) {
|
||||
$data = @include sprintf('%s/%s.php', rtrim($directory, '\\/'), $locale);
|
||||
|
||||
if ($data !== false) {
|
||||
$this->messages[$locale] = $data;
|
||||
$this->addResource('array', $this->messages[$locale], $locale);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of files matching a given locale prefix (or all if empty).
|
||||
*
|
||||
* @param string $prefix prefix required to filter result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocalesFiles($prefix = '')
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach ($this->getDirectories() as $directory) {
|
||||
$directory = rtrim($directory, '\\/');
|
||||
|
||||
foreach (glob("$directory/$prefix*.php") as $file) {
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of internally available locales and already loaded custom locales.
|
||||
* (It will ignore custom translator dynamic loading.)
|
||||
*
|
||||
* @param string $prefix prefix required to filter result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableLocales($prefix = '')
|
||||
{
|
||||
$locales = [];
|
||||
foreach ($this->getLocalesFiles($prefix) as $file) {
|
||||
$locales[] = substr($file, strrpos($file, '/') + 1, -4);
|
||||
}
|
||||
|
||||
return array_unique(array_merge($locales, array_keys($this->messages)));
|
||||
}
|
||||
|
||||
protected function translate(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
|
||||
{
|
||||
if ($domain === null) {
|
||||
$domain = 'messages';
|
||||
}
|
||||
|
||||
$catalogue = $this->getCatalogue($locale);
|
||||
$format = $this instanceof TranslatorStrongTypeInterface
|
||||
? $this->getFromCatalogue($catalogue, (string) $id, $domain)
|
||||
: $this->getCatalogue($locale)->get((string) $id, $domain); // @codeCoverageIgnore
|
||||
|
||||
if ($format instanceof Closure) {
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$count = (new ReflectionFunction($format))->getNumberOfRequiredParameters();
|
||||
} catch (ReflectionException $exception) {
|
||||
$count = 0;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $format(
|
||||
...array_values($parameters),
|
||||
...array_fill(0, max(0, $count - \count($parameters)), null)
|
||||
);
|
||||
}
|
||||
|
||||
return parent::trans($id, $parameters, $domain, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init messages language from matching file in Lang directory.
|
||||
*
|
||||
* @param string $locale
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function loadMessagesFromFile($locale)
|
||||
{
|
||||
return isset($this->messages[$locale]) || $this->resetMessages($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set messages of a locale and take file first if present.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param array $messages
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessages($locale, $messages)
|
||||
{
|
||||
$this->loadMessagesFromFile($locale);
|
||||
$this->addResource('array', $messages, $locale);
|
||||
$this->messages[$locale] = array_merge(
|
||||
$this->messages[$locale] ?? [],
|
||||
$messages
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set messages of the current locale and take file first if present.
|
||||
*
|
||||
* @param array $messages
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTranslations($messages)
|
||||
{
|
||||
return $this->setMessages($this->getLocale(), $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get messages of a locale, if none given, return all the
|
||||
* languages.
|
||||
*
|
||||
* @param string|null $locale
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages($locale = null)
|
||||
{
|
||||
return $locale === null ? $this->messages : $this->messages[$locale];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current translator locale and indicate if the source locale file exists
|
||||
*
|
||||
* @param string $locale locale ex. en
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$locale = preg_replace_callback('/[-_]([a-z]{2,}|\d{2,})/', function ($matches) {
|
||||
// _2-letters or YUE is a region, _3+-letters is a variant
|
||||
$upper = strtoupper($matches[1]);
|
||||
|
||||
if ($upper === 'YUE' || $upper === 'ISO' || \strlen($upper) < 3) {
|
||||
return "_$upper";
|
||||
}
|
||||
|
||||
return '_'.ucfirst($matches[1]);
|
||||
}, strtolower($locale));
|
||||
|
||||
$previousLocale = $this->getLocale();
|
||||
|
||||
if ($previousLocale === $locale && isset($this->messages[$locale])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
unset(static::$singletons[$previousLocale]);
|
||||
|
||||
if ($locale === 'auto') {
|
||||
$completeLocale = setlocale(LC_TIME, '0');
|
||||
$locale = preg_replace('/^([^_.-]+).*$/', '$1', $completeLocale);
|
||||
$locales = $this->getAvailableLocales($locale);
|
||||
|
||||
$completeLocaleChunks = preg_split('/[_.-]+/', $completeLocale);
|
||||
|
||||
$getScore = function ($language) use ($completeLocaleChunks) {
|
||||
return self::compareChunkLists($completeLocaleChunks, preg_split('/[_.-]+/', $language));
|
||||
};
|
||||
|
||||
usort($locales, function ($first, $second) use ($getScore) {
|
||||
return $getScore($second) <=> $getScore($first);
|
||||
});
|
||||
|
||||
$locale = $locales[0];
|
||||
}
|
||||
|
||||
if (isset($this->aliases[$locale])) {
|
||||
$locale = $this->aliases[$locale];
|
||||
}
|
||||
|
||||
// If subtag (ex: en_CA) first load the macro (ex: en) to have a fallback
|
||||
if (str_contains($locale, '_') &&
|
||||
$this->loadMessagesFromFile($macroLocale = preg_replace('/^([^_]+).*$/', '$1', $locale))
|
||||
) {
|
||||
parent::setLocale($macroLocale);
|
||||
}
|
||||
|
||||
if (!$this->loadMessagesFromFile($locale) && !$this->initializing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::setLocale($locale);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show locale on var_dump().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debugInfo()
|
||||
{
|
||||
return [
|
||||
'locale' => $this->getLocale(),
|
||||
];
|
||||
}
|
||||
|
||||
private static function compareChunkLists($referenceChunks, $chunks)
|
||||
{
|
||||
$score = 0;
|
||||
|
||||
foreach ($referenceChunks as $index => $chunk) {
|
||||
if (!isset($chunks[$index])) {
|
||||
$score++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strtolower($chunks[$index]) === strtolower($chunk)) {
|
||||
$score += 10;
|
||||
}
|
||||
}
|
||||
|
||||
return $score;
|
||||
}
|
||||
}
|
||||
+1129
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,471 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Carbon package.
|
||||
*
|
||||
* (c) Brian Nesbitt <brian@nesbot.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Carbon\Traits;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use DateTimeInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Trait Options.
|
||||
*
|
||||
* Embed base methods to change settings of Carbon classes.
|
||||
*
|
||||
* Depends on the following methods:
|
||||
*
|
||||
* @method static shiftTimezone($timezone) Set the timezone
|
||||
*/
|
||||
trait Options
|
||||
{
|
||||
use Localization;
|
||||
|
||||
/**
|
||||
* Customizable PHP_INT_SIZE override.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $PHPIntSize = PHP_INT_SIZE;
|
||||
|
||||
/**
|
||||
* First day of week.
|
||||
*
|
||||
* @var int|string
|
||||
*/
|
||||
protected static $weekStartsAt = CarbonInterface::MONDAY;
|
||||
|
||||
/**
|
||||
* Last day of week.
|
||||
*
|
||||
* @var int|string
|
||||
*/
|
||||
protected static $weekEndsAt = CarbonInterface::SUNDAY;
|
||||
|
||||
/**
|
||||
* Days of weekend.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $weekendDays = [
|
||||
CarbonInterface::SATURDAY,
|
||||
CarbonInterface::SUNDAY,
|
||||
];
|
||||
|
||||
/**
|
||||
* Format regex patterns.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected static $regexFormats = [
|
||||
'd' => '(3[01]|[12][0-9]|0[1-9])',
|
||||
'D' => '(Sun|Mon|Tue|Wed|Thu|Fri|Sat)',
|
||||
'j' => '([123][0-9]|[1-9])',
|
||||
'l' => '([a-zA-Z]{2,})',
|
||||
'N' => '([1-7])',
|
||||
'S' => '(st|nd|rd|th)',
|
||||
'w' => '([0-6])',
|
||||
'z' => '(36[0-5]|3[0-5][0-9]|[12][0-9]{2}|[1-9]?[0-9])',
|
||||
'W' => '(5[012]|[1-4][0-9]|0?[1-9])',
|
||||
'F' => '([a-zA-Z]{2,})',
|
||||
'm' => '(1[012]|0[1-9])',
|
||||
'M' => '([a-zA-Z]{3})',
|
||||
'n' => '(1[012]|[1-9])',
|
||||
't' => '(2[89]|3[01])',
|
||||
'L' => '(0|1)',
|
||||
'o' => '([1-9][0-9]{0,4})',
|
||||
'Y' => '([1-9]?[0-9]{4})',
|
||||
'y' => '([0-9]{2})',
|
||||
'a' => '(am|pm)',
|
||||
'A' => '(AM|PM)',
|
||||
'B' => '([0-9]{3})',
|
||||
'g' => '(1[012]|[1-9])',
|
||||
'G' => '(2[0-3]|1?[0-9])',
|
||||
'h' => '(1[012]|0[1-9])',
|
||||
'H' => '(2[0-3]|[01][0-9])',
|
||||
'i' => '([0-5][0-9])',
|
||||
's' => '([0-5][0-9])',
|
||||
'u' => '([0-9]{1,6})',
|
||||
'v' => '([0-9]{1,3})',
|
||||
'e' => '([a-zA-Z]{1,5})|([a-zA-Z]*\\/[a-zA-Z]*)',
|
||||
'I' => '(0|1)',
|
||||
'O' => '([+-](1[0123]|0[0-9])[0134][05])',
|
||||
'P' => '([+-](1[0123]|0[0-9]):[0134][05])',
|
||||
'p' => '(Z|[+-](1[0123]|0[0-9]):[0134][05])',
|
||||
'T' => '([a-zA-Z]{1,5})',
|
||||
'Z' => '(-?[1-5]?[0-9]{1,4})',
|
||||
'U' => '([0-9]*)',
|
||||
|
||||
// The formats below are combinations of the above formats.
|
||||
'c' => '(([1-9]?[0-9]{4})-(1[012]|0[1-9])-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[+-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP
|
||||
'r' => '(([a-zA-Z]{3}), ([123][0-9]|0[1-9]) ([a-zA-Z]{3}) ([1-9]?[0-9]{4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [+-](1[012]|0[0-9])([0134][05]))', // D, d M Y H:i:s O
|
||||
];
|
||||
|
||||
/**
|
||||
* Format modifiers (such as available in createFromFormat) regex patterns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $regexFormatModifiers = [
|
||||
'*' => '.+',
|
||||
' ' => '[ ]',
|
||||
'#' => '[;:\\/.,()-]',
|
||||
'?' => '([^a]|[a])',
|
||||
'!' => '',
|
||||
'|' => '',
|
||||
'+' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* Indicates if months should be calculated with overflow.
|
||||
* Global setting.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $monthsOverflow = true;
|
||||
|
||||
/**
|
||||
* Indicates if years should be calculated with overflow.
|
||||
* Global setting.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $yearsOverflow = true;
|
||||
|
||||
/**
|
||||
* Indicates if the strict mode is in use.
|
||||
* Global setting.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $strictModeEnabled = true;
|
||||
|
||||
/**
|
||||
* Function to call instead of format.
|
||||
*
|
||||
* @var string|callable|null
|
||||
*/
|
||||
protected static $formatFunction;
|
||||
|
||||
/**
|
||||
* Function to call instead of createFromFormat.
|
||||
*
|
||||
* @var string|callable|null
|
||||
*/
|
||||
protected static $createFromFormatFunction;
|
||||
|
||||
/**
|
||||
* Function to call instead of parse.
|
||||
*
|
||||
* @var string|callable|null
|
||||
*/
|
||||
protected static $parseFunction;
|
||||
|
||||
/**
|
||||
* Indicates if months should be calculated with overflow.
|
||||
* Specific setting.
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $localMonthsOverflow;
|
||||
|
||||
/**
|
||||
* Indicates if years should be calculated with overflow.
|
||||
* Specific setting.
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $localYearsOverflow;
|
||||
|
||||
/**
|
||||
* Indicates if the strict mode is in use.
|
||||
* Specific setting.
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $localStrictModeEnabled;
|
||||
|
||||
/**
|
||||
* Options for diffForHumans and forHumans methods.
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $localHumanDiffOptions;
|
||||
|
||||
/**
|
||||
* Format to use on string cast.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $localToStringFormat;
|
||||
|
||||
/**
|
||||
* Format to use on JSON serialization.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $localSerializer;
|
||||
|
||||
/**
|
||||
* Instance-specific macros.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $localMacros;
|
||||
|
||||
/**
|
||||
* Instance-specific generic macros.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $localGenericMacros;
|
||||
|
||||
/**
|
||||
* Function to call instead of format.
|
||||
*
|
||||
* @var string|callable|null
|
||||
*/
|
||||
protected $localFormatFunction;
|
||||
|
||||
/**
|
||||
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
|
||||
* You should rather use the ->settings() method.
|
||||
* @see settings
|
||||
*
|
||||
* Enable the strict mode (or disable with passing false).
|
||||
*
|
||||
* @param bool $strictModeEnabled
|
||||
*/
|
||||
public static function useStrictMode($strictModeEnabled = true)
|
||||
{
|
||||
static::$strictModeEnabled = $strictModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the strict mode is globally in use, false else.
|
||||
* (It can be overridden in specific instances.)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isStrictModeEnabled()
|
||||
{
|
||||
return static::$strictModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
|
||||
* You should rather use the ->settings() method.
|
||||
* Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants
|
||||
* are available for quarters, years, decade, centuries, millennia (singular and plural forms).
|
||||
* @see settings
|
||||
*
|
||||
* Indicates if months should be calculated with overflow.
|
||||
*
|
||||
* @param bool $monthsOverflow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function useMonthsOverflow($monthsOverflow = true)
|
||||
{
|
||||
static::$monthsOverflow = $monthsOverflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
|
||||
* You should rather use the ->settings() method.
|
||||
* Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants
|
||||
* are available for quarters, years, decade, centuries, millennia (singular and plural forms).
|
||||
* @see settings
|
||||
*
|
||||
* Reset the month overflow behavior.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function resetMonthsOverflow()
|
||||
{
|
||||
static::$monthsOverflow = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the month overflow global behavior (can be overridden in specific instances).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function shouldOverflowMonths()
|
||||
{
|
||||
return static::$monthsOverflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
|
||||
* You should rather use the ->settings() method.
|
||||
* Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants
|
||||
* are available for quarters, years, decade, centuries, millennia (singular and plural forms).
|
||||
* @see settings
|
||||
*
|
||||
* Indicates if years should be calculated with overflow.
|
||||
*
|
||||
* @param bool $yearsOverflow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function useYearsOverflow($yearsOverflow = true)
|
||||
{
|
||||
static::$yearsOverflow = $yearsOverflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
|
||||
* You should rather use the ->settings() method.
|
||||
* Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants
|
||||
* are available for quarters, years, decade, centuries, millennia (singular and plural forms).
|
||||
* @see settings
|
||||
*
|
||||
* Reset the month overflow behavior.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function resetYearsOverflow()
|
||||
{
|
||||
static::$yearsOverflow = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the month overflow global behavior (can be overridden in specific instances).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function shouldOverflowYears()
|
||||
{
|
||||
return static::$yearsOverflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set specific options.
|
||||
* - strictMode: true|false|null
|
||||
* - monthOverflow: true|false|null
|
||||
* - yearOverflow: true|false|null
|
||||
* - humanDiffOptions: int|null
|
||||
* - toStringFormat: string|Closure|null
|
||||
* - toJsonFormat: string|Closure|null
|
||||
* - locale: string|null
|
||||
* - timezone: \DateTimeZone|string|int|null
|
||||
* - macros: array|null
|
||||
* - genericMacros: array|null
|
||||
*
|
||||
* @param array $settings
|
||||
*
|
||||
* @return $this|static
|
||||
*/
|
||||
public function settings(array $settings)
|
||||
{
|
||||
$this->localStrictModeEnabled = $settings['strictMode'] ?? null;
|
||||
$this->localMonthsOverflow = $settings['monthOverflow'] ?? null;
|
||||
$this->localYearsOverflow = $settings['yearOverflow'] ?? null;
|
||||
$this->localHumanDiffOptions = $settings['humanDiffOptions'] ?? null;
|
||||
$this->localToStringFormat = $settings['toStringFormat'] ?? null;
|
||||
$this->localSerializer = $settings['toJsonFormat'] ?? null;
|
||||
$this->localMacros = $settings['macros'] ?? null;
|
||||
$this->localGenericMacros = $settings['genericMacros'] ?? null;
|
||||
$this->localFormatFunction = $settings['formatFunction'] ?? null;
|
||||
|
||||
if (isset($settings['locale'])) {
|
||||
$locales = $settings['locale'];
|
||||
|
||||
if (!\is_array($locales)) {
|
||||
$locales = [$locales];
|
||||
}
|
||||
|
||||
$this->locale(...$locales);
|
||||
}
|
||||
|
||||
if (isset($settings['innerTimezone'])) {
|
||||
return $this->setTimezone($settings['innerTimezone']);
|
||||
}
|
||||
|
||||
if (isset($settings['timezone'])) {
|
||||
return $this->shiftTimezone($settings['timezone']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current local settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings()
|
||||
{
|
||||
$settings = [];
|
||||
$map = [
|
||||
'localStrictModeEnabled' => 'strictMode',
|
||||
'localMonthsOverflow' => 'monthOverflow',
|
||||
'localYearsOverflow' => 'yearOverflow',
|
||||
'localHumanDiffOptions' => 'humanDiffOptions',
|
||||
'localToStringFormat' => 'toStringFormat',
|
||||
'localSerializer' => 'toJsonFormat',
|
||||
'localMacros' => 'macros',
|
||||
'localGenericMacros' => 'genericMacros',
|
||||
'locale' => 'locale',
|
||||
'tzName' => 'timezone',
|
||||
'localFormatFunction' => 'formatFunction',
|
||||
];
|
||||
|
||||
foreach ($map as $property => $key) {
|
||||
$value = $this->$property ?? null;
|
||||
|
||||
if ($value !== null && ($key !== 'locale' || $value !== 'en' || $this->localTranslator)) {
|
||||
$settings[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show truthy properties on var_dump().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debugInfo()
|
||||
{
|
||||
$infos = array_filter(get_object_vars($this), static function ($var) {
|
||||
return $var;
|
||||
});
|
||||
|
||||
foreach (['dumpProperties', 'constructedObjectId', 'constructed'] as $property) {
|
||||
if (isset($infos[$property])) {
|
||||
unset($infos[$property]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addExtraDebugInfos($infos);
|
||||
|
||||
return $infos;
|
||||
}
|
||||
|
||||
protected function addExtraDebugInfos(&$infos): void
|
||||
{
|
||||
if ($this instanceof DateTimeInterface) {
|
||||
try {
|
||||
if (!isset($infos['date'])) {
|
||||
$infos['date'] = $this->format(CarbonInterface::MOCK_DATETIME_FORMAT);
|
||||
}
|
||||
|
||||
if (!isset($infos['timezone'])) {
|
||||
$infos['timezone'] = $this->tzName;
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user