@@ -33,9 +33,9 @@ final class ComponentReflection extends \ReflectionClass
33
33
34
34
35
35
/**
36
- * Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent.
36
+ * Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter ] or annotation @persistent.
37
37
*/
38
- public function getPersistentParams (): array
38
+ public function getParameters (): array
39
39
{
40
40
$ params = &self ::$ ppCache [$ this ->getName ()];
41
41
if ($ params !== null ) {
@@ -46,26 +46,31 @@ public function getPersistentParams(): array
46
46
$ isPresenter = $ this ->isSubclassOf (Presenter::class);
47
47
$ defaults = $ this ->getDefaultProperties ();
48
48
foreach ($ this ->getProperties (\ReflectionProperty::IS_PUBLIC ) as $ prop ) {
49
- if (!$ prop ->isStatic ()
50
- && (self ::parseAnnotation ($ prop , 'persistent ' )
51
- || (PHP_VERSION_ID >= 80000 && $ prop ->getAttributes (Nette \Application \Attributes \Persistent::class)))
49
+ if ($ prop ->isStatic ()) {
50
+ continue ;
51
+ } elseif (self ::parseAnnotation ($ prop , 'persistent ' )
52
+ || (PHP_VERSION_ID >= 80000 && $ prop ->getAttributes (Nette \Application \Attributes \Persistent::class))
52
53
) {
53
54
$ default = $ defaults [$ prop ->getName ()] ?? null ;
54
55
$ params [$ prop ->getName ()] = [
55
56
'def ' => $ default ,
56
57
'type ' => self ::getPropertyType ($ prop , $ default ),
57
58
'since ' => $ isPresenter ? Nette \Utils \Reflection::getPropertyDeclaringClass ($ prop )->getName () : null ,
58
59
];
60
+ } elseif (PHP_VERSION_ID >= 80000 && $ prop ->getAttributes (Nette \Application \Attributes \Parameter::class)) {
61
+ $ params [$ prop ->getName ()] = [
62
+ 'type ' => (string ) ($ prop ->getType () ?? 'mixed ' ),
63
+ ];
59
64
}
60
65
}
61
66
62
67
if ($ this ->getParentClass ()->isSubclassOf (Component::class)) {
63
68
$ parent = new self ($ this ->getParentClass ()->getName ());
64
- foreach ($ parent ->getPersistentParams () as $ name => $ meta ) {
65
- if (isset ($ params [$ name ])) {
66
- $ params [$ name ]['since ' ] = $ meta ['since ' ];
67
- } else {
69
+ foreach ($ parent ->getParameters () as $ name => $ meta ) {
70
+ if (!isset ($ params [$ name ])) {
68
71
$ params [$ name ] = $ meta ;
72
+ } elseif (array_key_exists ('since ' , $ params [$ name ])) {
73
+ $ params [$ name ]['since ' ] = $ meta ['since ' ];
69
74
}
70
75
}
71
76
}
@@ -74,6 +79,17 @@ public function getPersistentParams(): array
74
79
}
75
80
76
81
82
+ /**
83
+ * Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent.
84
+ */
85
+ public function getPersistentParams (): array
86
+ {
87
+ return array_filter ($ this ->getParameters (), function ($ param ) {
88
+ return array_key_exists ('since ' , $ param );
89
+ });
90
+ }
91
+
92
+
77
93
public function getPersistentComponents (): array
78
94
{
79
95
$ class = $ this ->getName ();
@@ -200,7 +216,7 @@ public static function convertType(&$val, string $types): bool
200
216
$ scalars = ['string ' => 1 , 'int ' => 1 , 'float ' => 1 , 'bool ' => 1 , 'true ' => 1 , 'false ' => 1 , 'boolean ' => 1 , 'double ' => 1 , 'integer ' => 1 ];
201
217
$ testable = ['iterable ' => 1 , 'object ' => 1 , 'array ' => 1 , 'null ' => 1 ];
202
218
203
- foreach (explode ('| ' , $ types ) as $ type ) {
219
+ foreach (explode ('| ' , ltrim ( $ types, ' ? ' ) ) as $ type ) {
204
220
if (isset ($ scalars [$ type ])) {
205
221
$ ok = self ::castScalar ($ val , $ type );
206
222
} elseif (isset ($ testable [$ type ])) {
0 commit comments