Skip to content

Commit

Permalink
compatibility with nette/utils 4
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 19, 2023
1 parent a116e54 commit 12b4c12
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
18 changes: 17 additions & 1 deletion src/Forms/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
. '</label>'
. $wrapperEnd;
Expand Down Expand Up @@ -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'."
);
}
}
}

0 comments on commit 12b4c12

Please sign in to comment.