@@ -21,7 +21,7 @@ public function __construct(
2121 private ?string $ name = null ,
2222 private ?string $ template = null ,
2323 private bool $ exposePublicProps = true ,
24- private string $ attributesVar = 'attributes '
24+ private string $ attributesVar = 'attributes ' ,
2525 ) {
2626 }
2727
@@ -39,47 +39,56 @@ public function serviceConfig(): array
3939 }
4040
4141 /**
42- * @internal
42+ * @param object|class-string $component
4343 *
44- * @return \ReflectionMethod[]
44+ * @return ?\ReflectionMethod
45+ *
46+ * @internal
4547 */
46- public static function preMountMethods (object $ component ): iterable
48+ public static function mountMethod (object | string $ component ): ? \ ReflectionMethod
4749 {
48- return self ::attributeMethodsByPriorityFor ($ component , PreMount::class);
50+ foreach ((new \ReflectionClass ($ component ))->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ method ) {
51+ if ('mount ' === $ method ->getName ()) {
52+ return $ method ;
53+ }
54+ }
55+
56+ return null ;
4957 }
5058
5159 /**
52- * @internal
60+ * @param object|class-string $component
5361 *
5462 * @return \ReflectionMethod[]
63+ *
64+ * @internal
5565 */
56- public static function postMountMethods (object $ component ): iterable
66+ public static function postMountMethods (object | string $ component ): array
5767 {
5868 return self ::attributeMethodsByPriorityFor ($ component , PostMount::class);
5969 }
6070
6171 /**
62- * @internal
72+ * @param object|class-string $component
6373 *
6474 * @return \ReflectionMethod[]
75+ *
76+ * @internal
6577 */
66- protected static function attributeMethodsFor ( string $ attribute , object $ component ): \ Traversable
78+ public static function preMountMethods ( object | string $ component ): array
6779 {
68- foreach ((new \ReflectionClass ($ component ))->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ method ) {
69- if ($ method ->getAttributes ($ attribute , \ReflectionAttribute::IS_INSTANCEOF )[0 ] ?? null ) {
70- yield $ method ;
71- }
72- }
80+ return self ::attributeMethodsByPriorityFor ($ component , PreMount::class);
7381 }
7482
7583 /**
76- * @param class-string $attributeClass
84+ * @param object|class-string $component
85+ * @param class-string $attributeClass
7786 *
7887 * @return \ReflectionMethod[]
7988 *
8089 * @internal
8190 */
82- protected static function attributeMethodsByPriorityFor (object $ component , string $ attributeClass ): array
91+ protected static function attributeMethodsByPriorityFor (object | string $ component , string $ attributeClass ): array
8392 {
8493 $ methods = iterator_to_array (self ::attributeMethodsFor ($ attributeClass , $ component ));
8594
@@ -89,4 +98,18 @@ protected static function attributeMethodsByPriorityFor(object $component, strin
8998
9099 return array_reverse ($ methods );
91100 }
101+
102+ /**
103+ * @return \Traversable<\ReflectionMethod>
104+ *
105+ * @internal
106+ */
107+ protected static function attributeMethodsFor (string $ attribute , object |string $ component ): \Traversable
108+ {
109+ foreach ((new \ReflectionClass ($ component ))->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ method ) {
110+ if ($ method ->getAttributes ($ attribute , \ReflectionAttribute::IS_INSTANCEOF )[0 ] ?? null ) {
111+ yield $ method ;
112+ }
113+ }
114+ }
92115}
0 commit comments