@@ -33,9 +33,9 @@ final class ComponentReflection extends \ReflectionClass
3333
3434
3535 /**
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.
3737 */
38- public function getPersistentParams (): array
38+ public function getParameters (): array
3939 {
4040 $ params = &self ::$ ppCache [$ this ->getName ()];
4141 if ($ params !== null ) {
@@ -46,26 +46,31 @@ public function getPersistentParams(): array
4646 $ isPresenter = $ this ->isSubclassOf (Presenter::class);
4747 $ defaults = $ this ->getDefaultProperties ();
4848 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))
5253 ) {
5354 $ default = $ defaults [$ prop ->getName ()] ?? null ;
5455 $ params [$ prop ->getName ()] = [
5556 'def ' => $ default ,
5657 'type ' => self ::getPropertyType ($ prop , $ default ),
5758 'since ' => $ isPresenter ? Nette \Utils \Reflection::getPropertyDeclaringClass ($ prop )->getName () : null ,
5859 ];
60+ } elseif (PHP_VERSION_ID >= 80000 && $ prop ->getAttributes (Nette \Application \Attributes \Parameter::class)) {
61+ $ params [$ prop ->getName ()] = [
62+ 'type ' => (string ) ($ prop ->getType () ?? 'mixed ' ),
63+ ];
5964 }
6065 }
6166
6267 if ($ this ->getParentClass ()->isSubclassOf (Component::class)) {
6368 $ 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 ])) {
6871 $ params [$ name ] = $ meta ;
72+ } elseif (array_key_exists ('since ' , $ params [$ name ])) {
73+ $ params [$ name ]['since ' ] = $ meta ['since ' ];
6974 }
7075 }
7176 }
@@ -74,6 +79,17 @@ public function getPersistentParams(): array
7479 }
7580
7681
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+
7793 public function getPersistentComponents (): array
7894 {
7995 $ class = $ this ->getName ();
@@ -200,7 +216,7 @@ public static function convertType(&$val, string $types): bool
200216 $ scalars = ['string ' => 1 , 'int ' => 1 , 'float ' => 1 , 'bool ' => 1 , 'true ' => 1 , 'false ' => 1 , 'boolean ' => 1 , 'double ' => 1 , 'integer ' => 1 ];
201217 $ testable = ['iterable ' => 1 , 'object ' => 1 , 'array ' => 1 , 'null ' => 1 ];
202218
203- foreach (explode ('| ' , $ types ) as $ type ) {
219+ foreach (explode ('| ' , ltrim ( $ types, ' ? ' ) ) as $ type ) {
204220 if (isset ($ scalars [$ type ])) {
205221 $ ok = self ::castScalar ($ val , $ type );
206222 } elseif (isset ($ testable [$ type ])) {
0 commit comments