88#[\Attribute(\Attribute::TARGET_PARAMETER )]
99class Input
1010{
11- private \ReflectionClass $ class ;
1211 /**
1312 * @var array<string, Argument>
1413 */
15- private array $ arguments = [];
14+ public array $ arguments = [];
15+
1616 /**
1717 * @var array<string, Option>
1818 */
19- private array $ options = [];
19+ public array $ options = [];
20+
21+ private \ReflectionClass $ class ;
2022
2123 public static function tryFrom (\ReflectionParameter $ parameter ): ?self
2224 {
23- /** @var self $self */
25+ /** @var static $self */
2426 if (!$ self = ($ parameter ->getAttributes (self ::class, \ReflectionAttribute::IS_INSTANCEOF )[0 ] ?? null )?->newInstance()) {
2527 return null ;
2628 }
@@ -38,14 +40,18 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self
3840 $ self ->class = new \ReflectionClass ($ class );
3941
4042 foreach ($ self ->class ->getProperties () as $ property ) {
43+ if (!$ property ->isPublic () || $ property ->isStatic ()) {
44+ continue ;
45+ }
46+
4147 if ($ argument = Argument::tryFrom ($ property )) {
4248 $ self ->arguments [$ property ->name ] = $ argument ;
4349 } elseif ($ option = Option::tryFrom ($ property )) {
4450 $ self ->options [$ property ->name ] = $ option ;
4551 }
4652 }
4753
48- if ([] === $ self ->arguments && [] === $ self ->options ) {
54+ if (! $ self ->arguments && ! $ self ->options ) {
4955 throw new LogicException (\sprintf ('The input class "%s" must have at least one argument or option. ' , $ self ->class ->name ));
5056 }
5157
@@ -60,29 +66,13 @@ public function resolveValue(InputInterface $input): mixed
6066 $ instance = $ this ->class ->newInstanceWithoutConstructor ();
6167
6268 foreach ($ this ->arguments as $ name => $ argument ) {
63- $ this -> class -> getProperty ( $ name)-> setValue ( $ instance , $ argument ->resolveValue ($ input) );
69+ $ instance -> $ name = $ argument ->resolveValue ($ input );
6470 }
6571
6672 foreach ($ this ->options as $ name => $ option ) {
67- $ this -> class -> getProperty ( $ name)-> setValue ( $ instance , $ option ->resolveValue ($ input) );
73+ $ instance -> $ name = $ option ->resolveValue ($ input );
6874 }
6975
7076 return $ instance ;
7177 }
72-
73- /**
74- * @return Argument[]
75- */
76- public function getArguments (): array
77- {
78- return $ this ->arguments ;
79- }
80-
81- /**
82- * @return Option[]
83- */
84- public function getOptions (): array
85- {
86- return $ this ->options ;
87- }
8878}
0 commit comments