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
+36 -34
View File
@@ -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);
@@ -23,8 +19,10 @@ use Respect\Validation\Message\Formatter;
use Respect\Validation\Message\ParameterStringifier;
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
use function array_merge;
use function lcfirst;
use function sprintf;
use function str_replace;
use function trim;
use function ucfirst;
@@ -36,13 +34,6 @@ use function ucfirst;
*/
final class Factory
{
/**
* Default instance of the Factory.
*
* @var Factory
*/
private static $defaultInstance;
/**
* @var string[]
*/
@@ -63,11 +54,30 @@ final class Factory
*/
private $parameterStringifier;
/**
* Default instance of the Factory.
*
* @var Factory
*/
private static $defaultInstance;
public function __construct()
{
$this->parameterStringifier = new KeepOriginalStringName();
}
/**
* Returns the default instance of the Factory.
*/
public static function getDefaultInstance(): self
{
if (self::$defaultInstance === null) {
self::$defaultInstance = new self();
}
return self::$defaultInstance;
}
public function withRuleNamespace(string $rulesNamespace): self
{
$clone = clone $this;
@@ -100,26 +110,6 @@ final class Factory
return $clone;
}
/**
* Define the default instance of the Factory.
*/
public static function setDefaultInstance(self $defaultInstance): void
{
self::$defaultInstance = $defaultInstance;
}
/**
* Returns the default instance of the Factory.
*/
public static function getDefaultInstance(): self
{
if (self::$defaultInstance === null) {
self::$defaultInstance = new self();
}
return self::$defaultInstance;
}
/**
* Creates a rule.
*
@@ -165,7 +155,8 @@ final class Factory
if ($validatable->getName() !== null) {
/*$id = */$params['name'] = $validatable->getName();
}
foreach ($this->exceptionsNamespaces as $namespace) {
$exceptionNamespace = str_replace('\\Rules', '\\Exceptions', $reflection->getNamespaceName());
foreach (array_merge([$exceptionNamespace], $this->exceptionsNamespaces) as $namespace) {
try {
/** @var class-string<ValidationException> $exceptionName */
$exceptionName = $namespace . '\\' . $ruleName . 'Exception';
@@ -185,6 +176,14 @@ final class Factory
return new ValidationException($input, $id, $params, $formatter);
}
/**
* Define the default instance of the Factory.
*/
public static function setDefaultInstance(self $defaultInstance): void
{
self::$defaultInstance = $defaultInstance;
}
/**
* Creates a reflection based on class name.
*
@@ -193,6 +192,8 @@ final class Factory
*
* @throws InvalidClassException
* @throws ReflectionException
*
* @return ReflectionClass<ValidationException|Validatable|object>
*/
private function createReflectionClass(string $name, string $parentName): ReflectionClass
{
@@ -238,6 +239,7 @@ final class Factory
}
/**
* @param ReflectionObject|ReflectionClass<Validatable> $reflection
* @return mixed[]
*/
private function extractPropertiesValues(Validatable $validatable, ReflectionClass $reflection): array