From 12b4c12e9d65a4c97e10a37cee88fdd14db780b7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 9 Jan 2023 21:18:22 +0100 Subject: [PATCH] compatibility with nette/utils 4 --- composer.json | 2 +- src/Forms/Container.php | 4 ++-- src/Forms/Form.php | 2 +- src/Forms/Helpers.php | 18 +++++++++++++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 6d4a8dc09..a3bb333aa 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": ">=7.2 <8.3", "nette/component-model": "^3.0", "nette/http": "^3.1", - "nette/utils": "^3.2.1" + "nette/utils": "^3.2.5 || ~4.0.0" }, "require-dev": { "nette/application": "^3.0", diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 1eca7c5c1..70294a4a3 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -167,7 +167,7 @@ public function getUntrustedValues($returnType = ArrayHash::class, ?array $contr } elseif ($control instanceof self) { $type = $returnType === self::Array && !$control->mappedType ? self::Array - : ($rc->hasProperty($name) ? Nette\Utils\Reflection::getPropertyType($rc->getProperty($name)) : null); + : ($rc->hasProperty($name) ? Helpers::getSingleType($rc->getProperty($name)) : null); $obj->$name = $control->getUntrustedValues($type, $allowed ? null : $controls); } } @@ -237,7 +237,7 @@ public function validate(?array $controls = null): void foreach ($this->onValidate as $handler) { $params = Nette\Utils\Callback::toReflection($handler)->getParameters(); - $types = array_map([Nette\Utils\Reflection::class, 'getParameterType'], $params); + $types = array_map([Helpers::class, 'getSingleType'], $params); $args = isset($types[0]) && !$this instanceof $types[0] ? [$this->getUntrustedValues($types[0])] : [$this, isset($params[1]) ? $this->getUntrustedValues($types[1]) : null]; diff --git a/src/Forms/Form.php b/src/Forms/Form.php index f294479b1..b2a252fbc 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -447,7 +447,7 @@ private function invokeHandlers(iterable $handlers, $button = null): void { foreach ($handlers as $handler) { $params = Nette\Utils\Callback::toReflection($handler)->getParameters(); - $types = array_map([Nette\Utils\Reflection::class, 'getParameterType'], $params); + $types = array_map([Helpers::class, 'getSingleType'], $params); if (!isset($types[0])) { $arg0 = $button ?: $this; } elseif ($this instanceof $types[0]) { diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index f63feae41..4a15baef5 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -184,7 +184,7 @@ public static function createInputList( $input->value = $value; $res .= ($res === '' && $wrapperEnd === '' ? '' : $wrapper) . $labelTag . $label->attributes() . '>' - . $inputTag . $input->attributes() . (Html::$xhtml ? ' />' : '>') + . $inputTag . $input->attributes() . (isset(Html::$xhtml) && Html::$xhtml ? ' />' : '>') . ($caption instanceof Nette\HtmlStringable ? $caption : htmlspecialchars((string) $caption, ENT_NOQUOTES, 'UTF-8')) . '' . $wrapperEnd; @@ -269,4 +269,20 @@ public static function iniGetSize(string $name): int ? (int) $value << $units[$ch] : (int) $value; } + + + /** @internal */ + public static function getSingleType($reflection): ?string + { + $type = Nette\Utils\Type::fromReflection($reflection); + if (!$type) { + return null; + } elseif ($res = $type->getSingleName()) { + return $res; + } else { + throw new Nette\InvalidStateException( + Nette\Utils\Reflection::toString($reflection) . " has unsupported type '$type'." + ); + } + } }