Framework Update

This commit is contained in:
2024-01-31 22:15:08 +08:00
parent b5ff5e8b5f
commit 20678a6a0c
1459 changed files with 25954 additions and 16153 deletions
@@ -1,12 +1,8 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
@@ -1,19 +1,19 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Helpers;
use DateTime;
use DateTimeZone;
use function checkdate;
use function date_default_timezone_get;
use function date_parse_from_format;
use function preg_match;
@@ -34,13 +34,25 @@ trait CanValidateDateTime
'r' => 'D, d M Y H:i:s O',
];
$info = date_parse_from_format($exceptionalFormats[$format] ?? $format, $value);
$format = $exceptionalFormats[$format] ?? $format;
$info = date_parse_from_format($format, $value);
if (!$this->isDateTimeParsable($info)) {
return false;
}
if ($this->isDateFormat($format)) {
$formattedDate = DateTime::createFromFormat(
$format,
$value,
new DateTimeZone(date_default_timezone_get())
);
if ($formattedDate === false || $value !== $formattedDate->format($format)) {
return false;
}
return $this->isDateInformation($info);
}
@@ -48,7 +60,7 @@ trait CanValidateDateTime
}
/**
* @param int[] $info
* @param mixed[] $info
*/
private function isDateTimeParsable(array $info): bool
{
@@ -69,6 +81,6 @@ trait CanValidateDateTime
return checkdate((int) $info['month'], $info['day'], (int) $info['year']);
}
return checkdate($info['month'] ?: 1, $info['day'] ?: 1, $info['year'] ?: 1);
return checkdate($info['month'] ?: 1, 1, $info['year'] ?: 1);
}
}
@@ -1,12 +1,8 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
@@ -1,12 +1,8 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
@@ -0,0 +1,54 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Helpers;
use Respect\Validation\Exceptions\ComponentException;
use function file_exists;
use function sprintf;
final class CountryInfo
{
/**
* @var mixed[]
*/
private $data;
/**
* @var mixed[]
*/
private static $runtimeCache = [];
public function __construct(string $countryCode)
{
if (!isset(static::$runtimeCache[$countryCode])) {
$filename = __DIR__ . '/../../data/iso_3166-2/' . $countryCode . '.php';
if (!file_exists($filename)) {
throw new ComponentException(sprintf('"%s" is not a supported country code', $countryCode));
}
static::$runtimeCache[$countryCode] = require $filename;
}
$this->data = static::$runtimeCache[$countryCode];
}
public function getCountry(): string
{
return $this->data['country'];
}
/**
* @return string[]
*/
public function getSubdivisions(): array
{
return $this->data['subdivisions'];
}
}
@@ -0,0 +1,46 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Helpers;
use function file_exists;
use function mb_strtoupper;
final class DomainInfo
{
/**
* @var mixed[]
*/
private $data;
/**
* @var mixed[]
*/
private static $runtimeCache = [];
public function __construct(string $tld)
{
$tld = mb_strtoupper($tld);
if (!isset(static::$runtimeCache[$tld])) {
$filename = __DIR__ . '/../../data/domain/public-suffix/' . $tld . '.php';
static::$runtimeCache[$tld] = file_exists($filename) ? require $filename : [];
}
$this->data = static::$runtimeCache[$tld];
}
/**
* @return array<string>
*/
public function getPublicSuffixes(): array
{
return $this->data;
}
}
@@ -1,52 +0,0 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Helpers;
use Respect\Validation\Exceptions\ComponentException;
use function file_exists;
use function file_get_contents;
use function json_decode;
use function sprintf;
final class Subdivisions
{
/**
* @var mixed[]
*/
private $data;
public function __construct(string $countryCode)
{
$filename = __DIR__ . '/../../data/iso_3166-2/' . $countryCode . '.json';
if (!file_exists($filename)) {
throw new ComponentException(sprintf('"%s" is not a supported country code', $countryCode));
}
$this->data = (array) json_decode((string) file_get_contents($filename), true);
}
public function getCountry(): string
{
return $this->data['country'];
}
/**
* @return string[]
*/
public function getSubdivisions(): array
{
return $this->data['subdivisions'];
}
}