update lock clucknut
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 14s
Build, Push and Deploy / build-and-push (push) Successful in 3m14s
Build, Push and Deploy / deploy-staging (push) Successful in 25s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-18 20:32:18 +07:00
parent 4554035227
commit dcaf267458
3359 changed files with 153185 additions and 205489 deletions

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;
use function count;
@@ -16,21 +14,22 @@ final class Context
{
public bool $skipDefaults = false;
/** @var string[] */
/** @var list<int|string> */
public array $path = [];
public bool $isKey = false;
/** @var Message[] */
/** @var list<Message> */
public array $errors = [];
/** @var Message[] */
/** @var list<Message> */
public array $warnings = [];
/** @var array[] */
/** @var list<array{DynamicParameter, string, list<int|string>}> */
public array $dynamics = [];
/** @param array<string, mixed> $variables */
public function addError(string $message, string $code, array $variables = []): Message
{
$variables['isKey'] = $this->isKey;
@@ -38,6 +37,7 @@ public function addError(string $message, string $code, array $variables = []):
}
/** @param array<string, mixed> $variables */
public function addWarning(string $message, string $code, array $variables = []): Message
{
return $this->warnings[] = new Message($message, $code, $this->path, $variables);

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema\Elements;
use Nette;
@@ -20,6 +18,7 @@ final class AnyOf implements Schema
{
use Base;
/** @var mixed[] */
private array $set;

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema\Elements;
use Nette;
@@ -23,10 +21,10 @@ trait Base
private bool $required = false;
private mixed $default = null;
/** @var ?callable */
private $before;
/** @var ?\Closure(mixed): mixed */
private ?\Closure $before = null;
/** @var callable[] */
/** @var list<\Closure(mixed, Context): mixed> */
private array $transforms = [];
private ?string $deprecated = null;
@@ -45,9 +43,10 @@ public function required(bool $state = true): self
}
/** @param callable(mixed): mixed $handler */
public function before(callable $handler): self
{
$this->before = $handler;
$this->before = $handler(...);
return $this;
}
@@ -58,16 +57,18 @@ public function castTo(string $type): self
}
/** @param callable(mixed, Context): mixed $handler */
public function transform(callable $handler): self
{
$this->transforms[] = $handler;
$this->transforms[] = $handler(...);
return $this;
}
/** @param callable(mixed): bool $handler */
public function assert(callable $handler, ?string $description = null): self
{
$expected = $description ?: (is_string($handler) ? "$handler()" : '#' . count($this->transforms));
$expected = $description ?? (is_string($handler) ? "$handler()" : '#' . count($this->transforms));
return $this->transform(function ($value, Context $context) use ($handler, $description, $expected) {
if ($handler($value)) {
return $value;
@@ -146,7 +147,10 @@ private function doValidate(mixed $value, string $expected, Context $context): b
}
/** @deprecated use Nette\Schema\Validators::validateRange() */
/**
* @deprecated use Nette\Schema\Validators::validateRange()
* @param array{?float, ?float} $range
*/
private static function doValidateRange(mixed $value, array $range, Context $context, string $types = ''): bool
{
$isOk = $context->createChecker();

View File

@@ -1,19 +1,17 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema\Elements;
use Nette;
use Nette\Schema\Context;
use Nette\Schema\Helpers;
use Nette\Schema\Schema;
use function array_diff_key, array_fill_keys, array_key_exists, array_keys, array_map, array_merge, array_pop, array_values, is_array, is_object;
use function array_diff_key, array_fill_keys, array_key_exists, array_keys, array_map, array_merge, array_pop, array_values, is_array, is_object, strval;
final class Structure implements Schema
@@ -31,9 +29,7 @@ final class Structure implements Schema
private bool $skipDefaults = false;
/**
* @param Schema[] $shape
*/
/** @param Schema[] $shape */
public function __construct(array $shape)
{
(function (Schema ...$items) {})(...array_values($shape));
@@ -77,6 +73,7 @@ public function skipDefaults(bool $state = true): self
}
/** @param Schema[]|self $shape */
public function extend(array|self $shape): self
{
$shape = $shape instanceof self ? $shape->items : $shape;
@@ -84,6 +81,7 @@ public function extend(array|self $shape): self
}
/** @return Schema[] */
public function getShape(): array
{
return $this->items;
@@ -167,6 +165,7 @@ public function complete(mixed $value, Context $context): mixed
}
/** @param array<mixed> $value */
private function validateItems(array &$value, Context $context): void
{
$items = $this->items;
@@ -174,7 +173,7 @@ private function validateItems(array &$value, Context $context): void
if ($this->otherItems) {
$items += array_fill_keys($extraKeys, $this->otherItems);
} else {
$keys = array_map('strval', array_keys($items));
$keys = array_map(strval(...), array_keys($items));
foreach ($extraKeys as $key) {
$hint = Nette\Utils\Helpers::getSuggestion($keys, (string) $key);
$context->addError(

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema\Elements;
use Nette\Schema\Context;
@@ -189,6 +187,7 @@ public function complete(mixed $value, Context $context): mixed
}
/** @param array<mixed> $value */
private function validateItems(array &$value, Context $context): void
{
if (!$this->itemsValue) {

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;
use Nette;
@@ -32,6 +30,7 @@
*/
final class Expect
{
/** @param list<mixed> $args */
public static function __callStatic(string $name, array $args): Type
{
$type = new Type($name);
@@ -55,15 +54,14 @@ public static function anyOf(mixed ...$set): AnyOf
}
/**
* @param Schema[] $shape
*/
/** @param Schema[] $shape */
public static function structure(array $shape): Structure
{
return new Structure($shape);
}
/** @param array<string, Schema> $items */
public static function from(object $object, array $items = []): Structure
{
$ro = new \ReflectionObject($object);
@@ -72,8 +70,8 @@ public static function from(object $object, array $items = []): Structure
: $ro->getProperties();
foreach ($props as $prop) {
$item = &$items[$prop->getName()];
if (!$item) {
$name = $prop->getName();
if (!isset($items[$name])) {
$type = Helpers::getPropertyType($prop) ?? 'mixed';
$item = new Type($type);
if ($prop instanceof \ReflectionProperty ? $prop->isInitialized($object) : $prop->isOptional()) {
@@ -88,6 +86,7 @@ public static function from(object $object, array $items = []): Structure
} else {
$item->required();
}
$items[$name] = $item;
}
}
@@ -100,7 +99,8 @@ public static function from(object $object, array $items = []): Structure
*/
public static function array(?array $shape = []): Structure|Type
{
return Nette\Utils\Arrays::first($shape ?? []) instanceof Schema
$shape ??= [];
return Nette\Utils\Arrays::first($shape) instanceof Schema
? (new Structure($shape))->castTo('array')
: (new Type('array'))->default($shape);
}

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;
use Nette;
@@ -74,9 +72,9 @@ public static function getPropertyType(\ReflectionProperty|\ReflectionParameter
/**
* Returns an annotation value.
* @param \ReflectionProperty $ref
* @param \ReflectionClass<object>|\ReflectionProperty $ref
*/
public static function parseAnnotation(\Reflector $ref, string $name): ?string
public static function parseAnnotation(\ReflectionClass|\ReflectionProperty $ref, string $name): ?string
{
if (!Reflection::areCommentsAvailable()) {
throw new Nette\InvalidStateException('You have to enable phpDoc comments in opcode cache.');
@@ -121,12 +119,13 @@ public static function validateType(mixed $value, string $expected, Context $con
}
/** @param array{?float, ?float} $range */
public static function validateRange(mixed $value, array $range, Context $context, string $types = ''): void
{
if (is_array($value) || is_string($value)) {
[$length, $label] = is_array($value)
? [count($value), 'items']
: (in_array('unicode', explode('|', $types), true)
: (in_array('unicode', explode('|', $types), strict: true)
? [Nette\Utils\Strings::length($value), 'characters']
: [strlen($value), 'bytes']);
@@ -147,6 +146,7 @@ public static function validateRange(mixed $value, array $range, Context $contex
}
/** @param array{?float, ?float} $range */
public static function isInRange(mixed $value, array $range): bool
{
return ($range[0] === null || $value >= $range[0])
@@ -166,6 +166,7 @@ public static function validatePattern(string $value, string $pattern, Context $
}
/** @return \Closure(mixed): mixed */
public static function getCastStrategy(string $type): \Closure
{
if (Nette\Utils\Validators::isBuiltinType($type)) {

View File

@@ -1,16 +1,13 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;
use Nette;
use function implode, preg_last_error_msg, preg_replace_callback;
use function implode, preg_replace_callback;
final class Message
@@ -63,22 +60,15 @@ final class Message
/** @deprecated use Message::Deprecated */
public const DEPRECATED = self::Deprecated;
public string $message;
public string $code;
/** @var string[] */
public array $path;
/** @var string[] */
public array $variables;
public function __construct(string $message, string $code, array $path, array $variables = [])
{
$this->message = $message;
$this->code = $code;
$this->path = $path;
$this->variables = $variables;
public function __construct(
public string $message,
public string $code,
/** @var list<int|string> */
public array $path,
/** @var array<string, mixed> */
public array $variables = [],
) {
}
@@ -94,6 +84,6 @@ public function toString(): string
return preg_replace_callback('~( ?)%(\w+)%~', function ($m) use ($vars) {
[, $space, $key] = $m;
return $vars[$key] === null ? '' : $space . $vars[$key];
}, $this->message) ?? throw new Nette\InvalidStateException(preg_last_error_msg());
}, $this->message);
}
}

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;
use Nette;
@@ -17,6 +15,7 @@
*/
final class Processor
{
/** @var list<\Closure(Context): void> */
public array $onNewContext = [];
private Context $context;
private bool $skipDefaults = false;
@@ -45,6 +44,7 @@ public function process(Schema $schema, mixed $data): mixed
/**
* Normalizes and validates and merges multiple data. Result is a clean completed data.
* @param list<mixed> $dataset
* @throws ValidationException
*/
public function processMultiple(Schema $schema, array $dataset): mixed
@@ -65,9 +65,7 @@ public function processMultiple(Schema $schema, array $dataset): mixed
}
/**
* @return string[]
*/
/** @return list<string> */
public function getWarnings(): array
{
$res = [];

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;

View File

@@ -1,12 +1,10 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Schema;
use Nette;
@@ -17,23 +15,16 @@
*/
class ValidationException extends Nette\InvalidStateException
{
/** @var Message[] */
private array $messages;
/**
* @param Message[] $messages
*/
public function __construct(?string $message, array $messages = [])
{
parent::__construct($message ?: $messages[0]->toString());
$this->messages = $messages;
public function __construct(
?string $message,
/** @var list<Message> */
private array $messages = [],
) {
parent::__construct($message ?? $messages[0]->toString());
}
/**
* @return string[]
*/
/** @return list<string> */
public function getMessages(): array
{
$res = [];
@@ -45,9 +36,7 @@ public function getMessages(): array
}
/**
* @return Message[]
*/
/** @return list<Message> */
public function getMessageObjects(): array
{
return $this->messages;