Skip to content

Commit 5aacc0c

Browse files
committed
WIP
1 parent bfc6d6b commit 5aacc0c

File tree

11 files changed

+372
-310
lines changed

11 files changed

+372
-310
lines changed

src/TwigComponent/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 2.13.0
4+
5+
- Add search feature in `debug:twig-component` command.
6+
-
7+
38
## 2.12.0
49

510
- Added a `debug:twig-component` command.

src/TwigComponent/src/Attribute/AsTwigComponent.php

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/TwigComponent/src/Command/ComponentDebugCommand.php

Lines changed: 0 additions & 273 deletions
This file was deleted.

0 commit comments

Comments
 (0)