update lock clucknut
All checks were successful
All checks were successful
This commit is contained in:
18
vendor/nette/schema/src/Schema/Expect.php
vendored
18
vendor/nette/schema/src/Schema/Expect.php
vendored
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user