@@ -55,7 +55,7 @@ public function getPersistentParams(string $class = null): array
5555 ) {
5656 $ params [$ name ] = [
5757 'def ' => $ default ,
58- 'type ' => Nette \ Utils \Reflection ::getPropertyType ($ rp) ?: gettype ( $ default ),
58+ 'type ' => self ::getPropertyType ($ rp, $ default ),
5959 'since ' => $ isPresenter ? Nette \Utils \Reflection::getPropertyDeclaringClass ($ rp )->getName () : null ,
6060 ];
6161 }
@@ -190,7 +190,21 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a
190190 /**
191191 * Non data-loss type conversion.
192192 */
193- public static function convertType (&$ val , string $ type ): bool
193+ public static function convertType (&$ val , string $ types ): bool
194+ {
195+ foreach (explode ('| ' , $ types ) as $ type ) {
196+ if (self ::convertSingleType ($ val , $ type )) {
197+ return true ;
198+ }
199+ }
200+ return false ;
201+ }
202+
203+
204+ /**
205+ * Non data-loss type conversion.
206+ */
207+ private static function convertSingleType (&$ val , string $ type ): bool
194208 {
195209 static $ builtin = [
196210 'string ' => 1 , 'int ' => 1 , 'float ' => 1 , 'bool ' => 1 , 'array ' => 1 , 'object ' => 1 ,
@@ -259,12 +273,22 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array
259273
260274 public static function getParameterType (\ReflectionParameter $ param ): string
261275 {
262- return $ param ->hasType ()
263- ? $ param ->getType ()->getName ()
276+ $ type = $ param ->getType ();
277+ return $ type
278+ ? ($ type instanceof \ReflectionNamedType ? $ type ->getName () : (string ) $ type )
264279 : gettype ($ param ->isDefaultValueAvailable () ? $ param ->getDefaultValue () : null );
265280 }
266281
267282
283+ public static function getPropertyType (\ReflectionProperty $ prop , $ default ): string
284+ {
285+ $ type = PHP_VERSION_ID < 70400 ? null : $ prop ->getType ();
286+ return $ type
287+ ? ($ type instanceof \ReflectionNamedType ? $ type ->getName () : (string ) $ type )
288+ : gettype ($ default );
289+ }
290+
291+
268292 /**
269293 * Has class specified annotation?
270294 */
0 commit comments