From 0741beac0f26b13d603019ccd91ca5aead72567c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 20 May 2020 18:15:56 +0200 Subject: [PATCH] Presenter: added support for typehint 'object' --- src/Application/UI/ComponentReflection.php | 3 +++ tests/UI/ComponentReflection.convertType.phpt | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 4c472fd5e..e0a2d19e0 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -198,6 +198,9 @@ public static function convertType(&$val, string $type): bool if (empty($builtin[$type])) { return $val instanceof $type; + } elseif ($type === 'object') { + return is_object($val); + } elseif ($type === 'callable') { return false; diff --git a/tests/UI/ComponentReflection.convertType.phpt b/tests/UI/ComponentReflection.convertType.phpt index 0f3229ffd..9c91ae340 100644 --- a/tests/UI/ComponentReflection.convertType.phpt +++ b/tests/UI/ComponentReflection.convertType.phpt @@ -192,6 +192,23 @@ testIt('callable', 1); testIt('callable', 1.0); testIt('callable', 1.2); +testIt('object', null); +testIt('object', []); +testIt('object', $obj, $obj); +testIt('object', $var = function () {}, $var); +testIt('object', ''); +testIt('object', 'a'); +testIt('object', '1'); +testIt('object', '1.0'); +testIt('object', '1.1'); +testIt('object', '1a'); +testIt('object', true); +testIt('object', false); +testIt('object', 0); +testIt('object', 1); +testIt('object', 1.0); +testIt('object', 1.2); + testIt('stdClass', null); testIt('stdClass', []); testIt('stdClass', $obj, $obj);