diff --git a/src/Decorator.php b/src/Decorator.php index 954b0eb..bc716fc 100644 --- a/src/Decorator.php +++ b/src/Decorator.php @@ -31,6 +31,20 @@ public function __call($func, $args) throw new DecoratorError('Only public methods can be decorated!'); } + $params = $method->getParameters(); + + foreach ($params as $paramIndex => $param) { + $paramAttrs = $param->getAttributes(); + + foreach ($paramAttrs as $paramAttr) { + $paramAttrInst = $paramAttr->newInstance(); + + if ($paramAttrInst instanceof PythonDecorator) { + $paramAttrInst->bindTo($this)->wrapper($args[$paramIndex]); + } + } + } + $attributes = $method->getAttributes(); // } diff --git a/tests/GenericsTest.php b/tests/GenericsTest.php index 509bc34..dbb45cb 100644 --- a/tests/GenericsTest.php +++ b/tests/GenericsTest.php @@ -118,4 +118,24 @@ public function testPrimitiveStrItSelfFail(): void $box = new Box(); set_decorator_prop($box, 'str', 1); } + + public function testMethodParamAttributes(): void + { + $this->expectNotToPerformAssertions(); + + $box = new Box(); + $box(Pen::class); + + call_decorator_func_array([$box, 'addItem'], [new Pen]); + } + + public function testMethodParamAttributesFail(): void + { + $this->expectException(GenericError::class); + + $box = new Box(); + $box(Pen::class); + + call_decorator_func_array([$box, 'addItem'], [new Pencil]); + } } diff --git a/tests/examples/Box.php b/tests/examples/Box.php index 7876822..ccf7cdc 100644 --- a/tests/examples/Box.php +++ b/tests/examples/Box.php @@ -24,4 +24,12 @@ class Box #[Length(4)] public $size; + + #[ArrayOf(T::class)] + public $items; + + public function addItem(#[T] $item) + { + $this->items[] = $item; + } } \ No newline at end of file