Added PDF for pregenerated PDF

This commit is contained in:
Torsten Schulz
2023-12-27 18:19:27 +01:00
parent 547e4bbb6f
commit 82a68012ae
746 changed files with 139205 additions and 3620 deletions

View File

@@ -5125,8 +5125,7 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
* @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance
* @param Closure(): T $callback
*
* @return mixed
* @phpstan-return T
* @return T
*/
public static function withTestNow($testNow, $callback);

View File

@@ -238,6 +238,13 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
*/
public const END_MAX_ATTEMPTS = 10000;
/**
* Default date class of iteration items.
*
* @var string
*/
protected const DEFAULT_DATE_CLASS = Carbon::class;
/**
* The registered macros.
*
@@ -497,15 +504,16 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
$interval = null;
$start = null;
$end = null;
$dateClass = static::DEFAULT_DATE_CLASS;
foreach (explode('/', $iso) as $key => $part) {
if ($key === 0 && preg_match('/^R(\d*|INF)$/', $part, $match)) {
$parsed = \strlen($match[1]) ? (($match[1] !== 'INF') ? (int) $match[1] : INF) : null;
} elseif ($interval === null && $parsed = CarbonInterval::make($part)) {
$interval = $part;
} elseif ($start === null && $parsed = Carbon::make($part)) {
} elseif ($start === null && $parsed = $dateClass::make($part)) {
$start = $part;
} elseif ($end === null && $parsed = Carbon::make(static::addMissingParts($start ?? '', $part))) {
} elseif ($end === null && $parsed = $dateClass::make(static::addMissingParts($start ?? '', $part))) {
$end = $part;
} else {
throw new InvalidPeriodParameterException("Invalid ISO 8601 specification: $iso.");
@@ -701,7 +709,8 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
}
if ($this->startDate === null) {
$this->setStartDate(Carbon::now());
$dateClass = $this->dateClass;
$this->setStartDate($dateClass::now());
}
if ($this->dateInterval === null) {
@@ -1826,7 +1835,9 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
)(...$parameters));
}
if ($this->localStrictModeEnabled ?? Carbon::isStrictModeEnabled()) {
$dateClass = $this->dateClass;
if ($this->localStrictModeEnabled ?? $dateClass::isStrictModeEnabled()) {
throw new UnknownMethodException($method);
}
@@ -2685,7 +2696,9 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
!preg_match('/^R\d/', $value) &&
preg_match('/[a-z\d]/i', $value)
) {
return Carbon::parse($value, $this->tzName);
$dateClass = $this->dateClass;
return $dateClass::parse($value, $this->tzName);
}
}

View File

@@ -13,6 +13,13 @@ namespace Carbon;
class CarbonPeriodImmutable extends CarbonPeriod
{
/**
* Default date class of iteration items.
*
* @var string
*/
protected const DEFAULT_DATE_CLASS = CarbonImmutable::class;
/**
* Date class of iteration items.
*

View File

@@ -1,23 +0,0 @@
<?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\Doctrine;
use Doctrine\DBAL\Platforms\AbstractPlatform;
interface CarbonDoctrineType
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform);
public function convertToPHPValue($value, AbstractPlatform $platform);
public function convertToDatabaseValue($value, AbstractPlatform $platform);
}

View File

@@ -1,37 +0,0 @@
<?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\Doctrine;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class CarbonImmutableType extends DateTimeImmutableType implements CarbonDoctrineType
{
/**
* {@inheritdoc}
*
* @return string
*/
public function getName()
{
return 'carbon_immutable';
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
}

View File

@@ -1,37 +0,0 @@
<?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\Doctrine;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class CarbonType extends DateTimeType implements CarbonDoctrineType
{
/**
* {@inheritdoc}
*
* @return string
*/
public function getName()
{
return 'carbon';
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
}

View File

@@ -1,123 +0,0 @@
<?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\Doctrine;
use Carbon\Carbon;
use Carbon\CarbonInterface;
use DateTimeInterface;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Exception;
/**
* @template T of CarbonInterface
*/
trait CarbonTypeConverter
{
/**
* @return class-string<T>
*/
protected function getCarbonClassName(): string
{
return Carbon::class;
}
/**
* @return string
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$precision = $fieldDeclaration['precision'] ?: 10;
if ($fieldDeclaration['secondPrecision'] ?? false) {
$precision = 0;
}
if ($precision === 10) {
$precision = DateTimeDefaultPrecision::get();
}
$type = parent::getSQLDeclaration($fieldDeclaration, $platform);
if (!$precision) {
return $type;
}
if (str_contains($type, '(')) {
return preg_replace('/\(\d+\)/', "($precision)", $type);
}
[$before, $after] = explode(' ', "$type ");
return trim("$before($precision) $after");
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return T|null
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$class = $this->getCarbonClassName();
if ($value === null || is_a($value, $class)) {
return $value;
}
if ($value instanceof DateTimeInterface) {
return $class::instance($value);
}
$date = null;
$error = null;
try {
$date = $class::parse($value);
} catch (Exception $exception) {
$error = $exception;
}
if (!$date) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
'Y-m-d H:i:s.u or any format supported by '.$class.'::parse()',
$error
);
}
return $date;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return string|null
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return $value;
}
if ($value instanceof DateTimeInterface) {
return $value->format('Y-m-d H:i:s.u');
}
throw ConversionException::conversionFailedInvalidType(
$value,
$this->getName(),
['null', 'DateTime', 'Carbon']
);
}
}

View File

@@ -1,37 +0,0 @@
<?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\Doctrine;
class DateTimeDefaultPrecision
{
private static $precision = 6;
/**
* Change the default Doctrine datetime and datetime_immutable precision.
*
* @param int $precision
*/
public static function set(int $precision): void
{
self::$precision = $precision;
}
/**
* Get the default Doctrine datetime and datetime_immutable precision.
*
* @return int
*/
public static function get(): int
{
return self::$precision;
}
}

View File

@@ -1,24 +0,0 @@
<?php
/**
* Thanks to https://github.com/flaushi for his suggestion:
* https://github.com/doctrine/dbal/issues/2873#issuecomment-534956358
*/
namespace Carbon\Doctrine;
use Carbon\CarbonImmutable;
use Doctrine\DBAL\Types\VarDateTimeImmutableType;
class DateTimeImmutableType extends VarDateTimeImmutableType implements CarbonDoctrineType
{
/** @use CarbonTypeConverter<CarbonImmutable> */
use CarbonTypeConverter;
/**
* @return class-string<CarbonImmutable>
*/
protected function getCarbonClassName(): string
{
return CarbonImmutable::class;
}
}

View File

@@ -1,16 +0,0 @@
<?php
/**
* Thanks to https://github.com/flaushi for his suggestion:
* https://github.com/doctrine/dbal/issues/2873#issuecomment-534956358
*/
namespace Carbon\Doctrine;
use Carbon\Carbon;
use Doctrine\DBAL\Types\VarDateTimeType;
class DateTimeType extends VarDateTimeType implements CarbonDoctrineType
{
/** @use CarbonTypeConverter<Carbon> */
use CarbonTypeConverter;
}

View File

@@ -33,33 +33,87 @@
* - Marek Adamický
* - AlterwebStudio
*/
use Carbon\CarbonInterface;
$fromNow = function ($time) {
return 'o '.strtr($time, [
'hodina' => 'hodinu',
'minúta' => 'minútu',
'sekunda' => 'sekundu',
]);
};
$ago = function ($time) {
$replacements = [
'/\bhodina\b/' => 'hodinou',
'/\bminúta\b/' => 'minútou',
'/\bsekunda\b/' => 'sekundou',
'/\bdeň\b/u' => 'dňom',
'/\btýždeň\b/u' => 'týždňom',
'/\bmesiac\b/' => 'mesiacom',
'/\brok\b/' => 'rokom',
];
$replacementsPlural = [
'/\bhodiny\b/' => 'hodinami',
'/\bminúty\b/' => 'minútami',
'/\bsekundy\b/' => 'sekundami',
'/\bdni\b/' => 'dňami',
'/\btýždne\b/' => 'týždňami',
'/\bmesiace\b/' => 'mesiacmi',
'/\broky\b/' => 'rokmi',
];
foreach ($replacements + $replacementsPlural as $pattern => $replacement) {
$time = preg_replace($pattern, $replacement, $time);
}
return "pred $time";
};
return [
'year' => 'rok|:count roky|:count rokov',
'year' => ':count rok|:count roky|:count rokov',
'a_year' => 'rok|:count roky|:count rokov',
'y' => ':count r',
'month' => 'mesiac|:count mesiace|:count mesiacov',
'month' => ':count mesiac|:count mesiace|:count mesiacov',
'a_month' => 'mesiac|:count mesiace|:count mesiacov',
'm' => ':count m',
'week' => 'týždeň|:count týždne|:count týždňov',
'week' => ':count týždeň|:count týždne|:count týždňov',
'a_week' => 'týždeň|:count týždne|:count týždňov',
'w' => ':count t',
'day' => 'deň|:count dni|:count dní',
'day' => ':count deň|:count dni|:count dní',
'a_day' => 'deň|:count dni|:count dní',
'd' => ':count d',
'hour' => 'hodinu|:count hodiny|:count hodín',
'hour' => ':count hodina|:count hodiny|:count hodín',
'a_hour' => 'hodina|:count hodiny|:count hodín',
'h' => ':count h',
'minute' => 'minútu|:count minúty|:count minút',
'minute' => ':count minúta|:count minúty|:count minút',
'a_minute' => 'minúta|:count minúty|:count minút',
'min' => ':count min',
'second' => 'sekundu|:count sekundy|:count sekúnd',
'a_second' => 'pár sekúnd|:count sekundy|:count sekúnd',
'second' => ':count sekunda|:count sekundy|:count sekúnd',
'a_second' => 'sekunda|:count sekundy|:count sekúnd',
's' => ':count s',
'ago' => 'pred :time',
'from_now' => 'o :time',
'after' => ':time po',
'millisecond' => ':count milisekunda|:count milisekundy|:count milisekúnd',
'a_millisecond' => 'milisekunda|:count milisekundy|:count milisekúnd',
'ms' => ':count ms',
'microsecond' => ':count mikrosekunda|:count mikrosekundy|:count mikrosekúnd',
'a_microsecond' => 'mikrosekunda|:count mikrosekundy|:count mikrosekúnd',
'µs' => ':count µs',
'ago' => $ago,
'from_now' => $fromNow,
'before' => ':time pred',
'year_ago' => 'rokom|:count rokmi|:count rokmi',
'month_ago' => 'mesiacom|:count mesiacmi|:count mesiacmi',
'week_ago' => 'týždňom|:count týždňami|:count týždňami',
'day_ago' => 'dňom|:count dňami|:count dňami',
'hour_ago' => 'hodinou|:count hodinami|:count hodinami',
'minute_ago' => 'minútou|:count minútami|:count minútami',
'second_ago' => 'sekundou|:count sekundami|:count sekundami',
'after' => ':time po',
'hour_after' => ':count hodinu|:count hodiny|:count hodín',
'minute_after' => ':count minútu|:count minúty|:count minút',
'second_after' => ':count sekundu|:count sekundy|:count sekúnd',
'hour_before' => ':count hodinu|:count hodiny|:count hodín',
'minute_before' => ':count minútu|:count minúty|:count minút',
'second_before' => ':count sekundu|:count sekundy|:count sekúnd',
'first_day_of_week' => 1,
'day_of_first_week_of_year' => 4,
'list' => [', ', ' a '],
@@ -74,6 +128,24 @@ return [
'LLL' => 'D. M. HH:mm',
'LLLL' => 'dddd D. MMMM YYYY HH:mm',
],
'calendar' => [
'sameDay' => '[dnes o] LT',
'nextDay' => '[zajtra o] LT',
'lastDay' => '[včera o] LT',
'nextWeek' => 'dddd [o] LT',
'lastWeek' => static function (CarbonInterface $date) {
switch ($date->dayOfWeek) {
case 1:
case 2:
case 4:
case 5:
return '[minulý] dddd [o] LT'; //pondelok/utorok/štvrtok/piatok
default:
return '[minulá] dddd [o] LT';
}
},
'sameElse' => 'L',
],
'weekdays' => ['nedeľa', 'pondelok', 'utorok', 'streda', 'štvrtok', 'piatok', 'sobota'],
'weekdays_short' => ['ned', 'pod', 'uto', 'str', 'štv', 'pia', 'sob'],
'weekdays_min' => ['ne', 'po', 'ut', 'st', 'št', 'pi', 'so'],

View File

@@ -70,11 +70,9 @@ abstract class AbstractMacro implements BuiltinMethodReflection
/**
* Macro constructor.
*
* @param string $className
* @phpstan-param class-string $className
*
* @param string $methodName
* @param callable $macro
* @param class-string $className
* @param string $methodName
* @param callable $macro
*/
public function __construct(string $className, string $methodName, $macro)
{

View File

@@ -36,10 +36,8 @@ final class MacroScanner
/**
* Return true if the given pair class-method is a Carbon macro.
*
* @param string $className
* @phpstan-param class-string $className
*
* @param string $methodName
* @param class-string $className
* @param string $methodName
*
* @return bool
*/
@@ -61,10 +59,8 @@ final class MacroScanner
/**
* Return the Macro for a given pair class-method.
*
* @param string $className
* @phpstan-param class-string $className
*
* @param string $methodName
* @param class-string $className
* @param string $methodName
*
* @throws ReflectionException
*

View File

@@ -57,7 +57,6 @@ trait Rounding
'microsecond' => [0, 999999],
]);
$factor = 1;
$initialMonth = $this->month;
if ($normalizedUnit === 'week') {
$normalizedUnit = 'day';
@@ -130,16 +129,13 @@ trait Rounding
$normalizedValue = floor($function(($value - $minimum) / $precision) * $precision + $minimum);
/** @var CarbonInterface $result */
$result = $this->$normalizedUnit($normalizedValue);
$result = $this;
foreach ($changes as $unit => $value) {
$result = $result->$unit($value);
}
return $normalizedUnit === 'month' && $precision <= 1 && abs($result->month - $initialMonth) === 2
// Re-run the change in case an overflow occurred
? $result->$normalizedUnit($normalizedValue)
: $result;
return $result->$normalizedUnit($normalizedValue);
}
/**

View File

@@ -124,8 +124,7 @@ trait Test
* @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance
* @param Closure(): T $callback
*
* @return mixed
* @phpstan-return T
* @return T
*/
public static function withTestNow($testNow, $callback)
{

View File

@@ -66,7 +66,7 @@ class TranslatorImmutable extends Translator
/**
* @codeCoverageIgnore
*/
public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory)
public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory): void
{
$this->disallowMutation(__METHOD__);