From 61f4585b259a6c6cc975808f4ee77cc7d8370d09 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 29 Jul 2023 22:19:38 +0200 Subject: [PATCH 1/4] Migrate to new reflection API --- composer.json | 1 + src/main/php/inject/Injector.class.php | 55 ++++++++----------- .../AnnotatedConstructorTest.class.php | 28 +++++----- .../inject/unittest/NewInstanceTest.class.php | 19 ++++--- 4 files changed, 48 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index 0ffd094..bef28e1 100755 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "keywords": ["module", "xp"], "require" : { "xp-framework/core": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0", + "xp-framework/reflection": "^2.0", "php" : ">=7.0.0" }, "require-dev" : { diff --git a/src/main/php/inject/Injector.class.php b/src/main/php/inject/Injector.class.php index f5015e8..1c6296c 100755 --- a/src/main/php/inject/Injector.class.php +++ b/src/main/php/inject/Injector.class.php @@ -1,7 +1,7 @@ getParameters() as $i => $param) { - $name= $param->getName(); + foreach ($routine->parameters() as $name => $param) { if (isset($named[$name])) { $args[]= $named[$name]; continue; } - if ($param->hasAnnotation('inject')) { - $inject= $param->getAnnotation('inject'); - } else if (0 === $i) { - $inject= $routine->hasAnnotation('inject') ? $routine->getAnnotation('inject') : null; + if ($annotation= $param->annotation(Inject::class)) { + $inject= $annotation->arguments(); + } else if (0 === $param->position() && $annotation= $routine->annotation(Inject::class)) { + $inject= $annotation->arguments(); } else { - $inject= null; + $inject= []; } - if (is_array($inject)) { - $type= isset($inject['type']) ? Type::forName($inject['type']) : ($param->getTypeRestriction() ?: $param->getType()); - $lookup= $this->binding($type, $inject['name'] ?? null); - } else { - $type= $param->getTypeRestriction() ?: $param->getType(); - $lookup= $this->binding($type, $inject); - } + $type= isset($inject['type']) ? Type::forName($inject['type']) : $param->constraint()->type(); + $lookup= $this->binding($type, $inject['name'] ?? $inject[0] ?? null); if ($binding= $this->provided($lookup) ?? $this->provided($this->binding($type, $name))) { $args[]= $binding->resolve($this); - } else if ($param->isOptional()) { - $args[]= $param->getDefaultValue(); + } else if ($param->optional()) { + $args[]= $param->default(); } else { return new ProvisionException(sprintf( 'No bound value for type %s%s in %s\'s %s() parameter %s', $type->getName(), isset($inject['name']) ? ' named "'.$inject['name'].'"' : '', - $routine->getDeclaringClass()->getName(), - $routine->getName(), - $param->getName() + $routine->declaredIn()->name(), + $routine->name(), + $name )); } } @@ -160,9 +154,9 @@ private function argumentsOf($routine, $named= []) { * @throws inject.ProvisionException */ private function instanceOf($class, $named= []) { - if (!$class->hasConstructor()) return new InstanceBinding($class->newInstance()); + $t= Reflection::type($class); + if (null === ($constructor= $t->constructor())) return new InstanceBinding($class->newInstance()); - $constructor= $class->getConstructor(); $arguments= $this->argumentsOf($constructor, $named); if (!$this->provided($arguments)) return $arguments; @@ -170,8 +164,6 @@ private function instanceOf($class, $named= []) { // should not be simply returned as we risk them being overlooked! try { return new InstanceBinding($constructor->newInstance($arguments->resolve($this))); - } catch (TargetInvocationException $e) { - throw new ProvisionException('Error creating an instance of '.$class->getName(), $e->getCause()); } catch (Throwable $e) { throw new ProvisionException('Error creating an instance of '.$class->getName(), $e); } @@ -183,7 +175,6 @@ private function instanceOf($class, $named= []) { * @param string|lang.Type $type * @param ?string $name * @return inject.Binding - * @throws inject.ProvisionException */ public function binding($type, $name= null) { $t= $type instanceof Type ? $type : Type::forName($type); @@ -202,13 +193,13 @@ public function binding($type, $name= null) { return $this->binding($t->underlyingType(), $name); } else if (self::$PROVIDER->isAssignableFrom($t)) { $literal= $t->genericArguments()[0]->literal(); - if (isset($this->bindings[$literal][$name])) { - return new InstanceBinding($this->bindings[$literal][$name]->provider($this)); + if ($binding= $this->bindings[$literal][$name] ?? null) { + return new InstanceBinding($binding->provider($this)); } } else { $literal= $t->literal(); - if (isset($this->bindings[$literal][$name])) { - return $this->bindings[$literal][$name]; + if ($binding= $this->bindings[$literal][$name] ?? null) { + return $binding; } else if (null === $name && $t instanceof XPClass && !($t->isInterface() || $t->getModifiers() & MODIFIER_ABSTRACT)) { return $this->instanceOf($t); } @@ -235,7 +226,7 @@ public function get($type, $name= null) { /** * Retrieve args for a given routine. * - * @param lang.reflect.Routine $routine + * @param lang.reflection.Routine $routine * @param [:var] $named Named arguments * @return var[] * @throws inject.ProvisionException diff --git a/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php b/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php index 2e25ec7..8c7dab1 100755 --- a/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php +++ b/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php @@ -12,7 +12,7 @@ class AnnotatedConstructorTest extends AnnotationsTest { public function with_inject_annotation_and_type() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject(["type" => "inject.unittest.AnnotationsTest"])] __construct' => function($param) { + '#[\inject\Inject(type: "inject.unittest.AnnotationsTest")] __construct' => function($param) { $this->injected= $param; } ])); @@ -23,7 +23,7 @@ public function with_inject_annotation_and_type() { public function with_inject_annotation_and_restriction() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject] __construct' => function(AnnotationsTest $param) { $this->injected= $param; } + '#[\inject\Inject] __construct' => function(AnnotationsTest $param) { $this->injected= $param; } ])); Assert::equals($this, $this->inject->get(Value::class)->injected); } @@ -32,7 +32,7 @@ public function with_inject_annotation_and_restriction() { public function optional_bound_parameter() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject] __construct' => function(AnnotationsTest $test= null) { $this->injected= $test; } + '#[\inject\Inject] __construct' => function(AnnotationsTest $test= null) { $this->injected= $test; } ])); Assert::equals($this, $this->inject->get(Value::class)->injected); } @@ -41,7 +41,7 @@ public function optional_bound_parameter() { public function optional_unbound_parameter() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject] __construct' => function(AnnotationsTest $test, $verify= true) { $this->injected= [$test, $verify]; } + '#[\inject\Inject] __construct' => function(AnnotationsTest $test, $verify= true) { $this->injected= [$test, $verify]; } ])); Assert::equals([$this, true], $this->inject->get(Value::class)->injected); } @@ -51,7 +51,7 @@ public function optional_bound_named_parameter() { $this->inject->bind('string', 'Test', 'name'); $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject] __construct' => function(string $name= '') { $this->injected= $name; } + '#[\inject\Inject] __construct' => function(string $name= '') { $this->injected= $name; } ])); Assert::equals('Test', $this->inject->get(Value::class)->injected); } @@ -60,7 +60,7 @@ public function optional_bound_named_parameter() { public function with_inject_annotation_and_multiple_parameters() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject] __construct' => function(AnnotationsTest $test, Storage $storage) { + '#[\inject\Inject] __construct' => function(AnnotationsTest $test, Storage $storage) { $this->injected= [$test, $storage]; } ])); @@ -73,9 +73,9 @@ public function with_inject_parameter_annotations() { public $injected; public function __construct( - #[Inject] + #[\inject\Inject] \inject\unittest\AnnotationsTest $test, - #[Inject(name: "EUR")] + #[\inject\Inject(name: "EUR")] \util\Currency $cur ) { $this->injected= [$test, $cur]; @@ -89,11 +89,11 @@ public function with_inject_annotation_and_inject_parameter_annotations() { $this->inject->bind(Value::class, $this->newInstance('{ public $injected; - #[Inject] + #[\inject\Inject] public function __construct( \inject\unittest\AnnotationsTest $test, \inject\unittest\fixture\Storage $storage, - #[Inject(name: "name", type: "string")] + #[\inject\Inject(name: "name", type: "string")] $name ) { $this->injected= [$test, $storage, $name]; @@ -105,7 +105,7 @@ public function __construct( #[Test, Expect(class: ProvisionException::class, message: '/No bound value for type lang.Runnable/')] public function injecting_unbound_into_constructor_via_method_annotation() { $this->inject->bind(Value::class, $this->newInstance([ - '#[Inject] __construct' => function(Runnable $param) { /* Empty */ } + '#[\inject\Inject] __construct' => function(Runnable $param) { /* Empty */ } ])); $this->inject->get(Value::class); } @@ -113,9 +113,9 @@ public function injecting_unbound_into_constructor_via_method_annotation() { #[Test, Expect(class: ProvisionException::class, message: '/No bound value for type lang.Runnable/')] public function injecting_unbound_into_constructor_via_parameter_annotation() { $this->inject->bind(Value::class, $this->newInstance('{ - #[Inject] + #[\inject\Inject] public function __construct( - #[Inject] + #[\inject\Inject] \lang\Runnable $param ) { } }')); @@ -154,7 +154,7 @@ public function annotation_is_optional_multiple_parameters() { public function name_defaults_to_parameter() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[Inject] __construct' => function(AnnotationsTest $test, Storage $storage, string $name) { + '#[\inject\Inject] __construct' => function(AnnotationsTest $test, Storage $storage, string $name) { $this->injected= [$test, $storage, $name]; } ])); diff --git a/src/test/php/inject/unittest/NewInstanceTest.class.php b/src/test/php/inject/unittest/NewInstanceTest.class.php index b91b0cf..6e6d200 100755 --- a/src/test/php/inject/unittest/NewInstanceTest.class.php +++ b/src/test/php/inject/unittest/NewInstanceTest.class.php @@ -2,7 +2,8 @@ use inject\unittest\fixture\{FileSystem, Storage}; use inject\{Injector, ProvisionException}; -use lang\{ClassLoader, IllegalAccessException, Runnable}; +use lang\reflection\CannotInstantiate; +use lang\{ClassLoader, XPException, Runnable}; use test\{Assert, Before, Expect, Test}; use util\Currency; @@ -49,7 +50,7 @@ public function storage() { public function newInstance_performs_injection() { $inject= (new Injector())->bind(Storage::class, $this->storage); $fixture= $this->newFixture([ - '#[Inject] __construct' => function(Storage $param) { $this->injected= $param; } + '#[\inject\Inject] __construct' => function(Storage $param) { $this->injected= $param; } ]); Assert::equals($this->storage, $inject->newInstance($fixture)->injected); @@ -59,7 +60,7 @@ public function newInstance_performs_injection() { public function newInstance_performs_named_injection_using_array_form() { $inject= (new Injector())->bind(Storage::class, $this->storage, 'test'); $fixture= $this->newFixture([ - '#[Inject(["name" => "test"])] __construct' => function(Storage $param) { $this->injected= $param; } + '#[\inject\Inject(name: "test")] __construct' => function(Storage $param) { $this->injected= $param; } ]); Assert::equals($this->storage, $inject->newInstance($fixture)->injected); @@ -69,7 +70,7 @@ public function newInstance_performs_named_injection_using_array_form() { public function newInstance_performs_named_injection_using_string_form() { $inject= (new Injector())->bind(Storage::class, $this->storage, 'test'); $fixture= $this->newFixture([ - '#[Inject("test")] __construct' => function(Storage $param) { $this->injected= $param; } + '#[\inject\Inject("test")] __construct' => function(Storage $param) { $this->injected= $param; } ]); Assert::equals($this->storage, $inject->newInstance($fixture)->injected); @@ -111,16 +112,16 @@ public function newInstance_performs_partial_injection_with_optional_parameter() $inject= new Injector(); $inject->bind(Storage::class, $this->storage); $fixture= $this->newFixture([ - '#[Inject] __construct' => function(Storage $param, $verify= true) { $this->injected= [$param, $verify]; } + '#[\inject\Inject] __construct' => function(Storage $param, $verify= true) { $this->injected= [$param, $verify]; } ]); Assert::equals([$this->storage, true], $inject->newInstance($fixture)->injected); } - #[Test, Expect(class: IllegalAccessException::class, message: '/Cannot invoke private constructor/')] - public function newInstance_catches_iae_when_creating_class_instances() { + #[Test, Expect(class: CannotInstantiate::class, message: '/Cannot instantiate .+/')] + public function newInstance_catches_cannot_instantiate_when_creating_class_instances() { $this->newInstance(new Injector(), $this->newFixture('{ - #[Inject] + #[\inject\Inject] private function __construct() { } }')); } @@ -128,7 +129,7 @@ private function __construct() { } #[Test, Expect(class: ProvisionException::class, message: '/No bound value for type string named "endpoint"/')] public function newInstance_throws_when_value_for_required_parameter_not_found() { $this->newInstance(new Injector(), $this->newFixture('{ - #[Inject(["type" => "string", "name" => "endpoint"])] + #[\inject\Inject(type: "string", name: "endpoint")] public function __construct($uri) { } }')); } From b21fffbca33526994c52ce97497c7b743bca4bc8 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 29 Jul 2023 22:21:29 +0200 Subject: [PATCH 2/4] QA: Remove unused import --- src/main/php/inject/Injector.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/php/inject/Injector.class.php b/src/main/php/inject/Injector.class.php index 1c6296c..5928c4a 100755 --- a/src/main/php/inject/Injector.class.php +++ b/src/main/php/inject/Injector.class.php @@ -1,6 +1,5 @@ Date: Sun, 30 Jul 2023 09:19:22 +0200 Subject: [PATCH 3/4] QA: Simplify newInstance() developer experience --- .../AnnotatedConstructorTest.class.php | 34 +++++++++---------- .../inject/unittest/AnnotationsTest.class.php | 3 +- .../inject/unittest/NewInstanceTest.class.php | 16 ++++----- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php b/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php index 8c7dab1..4ad77c8 100755 --- a/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php +++ b/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php @@ -12,7 +12,7 @@ class AnnotatedConstructorTest extends AnnotationsTest { public function with_inject_annotation_and_type() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject(type: "inject.unittest.AnnotationsTest")] __construct' => function($param) { + '#[Inject(type: "inject.unittest.AnnotationsTest")] __construct' => function($param) { $this->injected= $param; } ])); @@ -23,7 +23,7 @@ public function with_inject_annotation_and_type() { public function with_inject_annotation_and_restriction() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject] __construct' => function(AnnotationsTest $param) { $this->injected= $param; } + '#[Inject] __construct' => function(AnnotationsTest $param) { $this->injected= $param; } ])); Assert::equals($this, $this->inject->get(Value::class)->injected); } @@ -32,7 +32,7 @@ public function with_inject_annotation_and_restriction() { public function optional_bound_parameter() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject] __construct' => function(AnnotationsTest $test= null) { $this->injected= $test; } + '#[Inject] __construct' => function(AnnotationsTest $test= null) { $this->injected= $test; } ])); Assert::equals($this, $this->inject->get(Value::class)->injected); } @@ -41,7 +41,7 @@ public function optional_bound_parameter() { public function optional_unbound_parameter() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject] __construct' => function(AnnotationsTest $test, $verify= true) { $this->injected= [$test, $verify]; } + '#[Inject] __construct' => function(AnnotationsTest $test, $verify= true) { $this->injected= [$test, $verify]; } ])); Assert::equals([$this, true], $this->inject->get(Value::class)->injected); } @@ -51,7 +51,7 @@ public function optional_bound_named_parameter() { $this->inject->bind('string', 'Test', 'name'); $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject] __construct' => function(string $name= '') { $this->injected= $name; } + '#[Inject] __construct' => function(string $name= '') { $this->injected= $name; } ])); Assert::equals('Test', $this->inject->get(Value::class)->injected); } @@ -60,7 +60,7 @@ public function optional_bound_named_parameter() { public function with_inject_annotation_and_multiple_parameters() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject] __construct' => function(AnnotationsTest $test, Storage $storage) { + '#[Inject] __construct' => function(AnnotationsTest $test, Storage $storage) { $this->injected= [$test, $storage]; } ])); @@ -73,9 +73,9 @@ public function with_inject_parameter_annotations() { public $injected; public function __construct( - #[\inject\Inject] - \inject\unittest\AnnotationsTest $test, - #[\inject\Inject(name: "EUR")] + #[Inject] + unittest\AnnotationsTest $test, + #[Inject(name: "EUR")] \util\Currency $cur ) { $this->injected= [$test, $cur]; @@ -89,11 +89,11 @@ public function with_inject_annotation_and_inject_parameter_annotations() { $this->inject->bind(Value::class, $this->newInstance('{ public $injected; - #[\inject\Inject] + #[Inject] public function __construct( - \inject\unittest\AnnotationsTest $test, - \inject\unittest\fixture\Storage $storage, - #[\inject\Inject(name: "name", type: "string")] + unittest\AnnotationsTest $test, + unittest\fixture\Storage $storage, + #[Inject(name: "name", type: "string")] $name ) { $this->injected= [$test, $storage, $name]; @@ -105,7 +105,7 @@ public function __construct( #[Test, Expect(class: ProvisionException::class, message: '/No bound value for type lang.Runnable/')] public function injecting_unbound_into_constructor_via_method_annotation() { $this->inject->bind(Value::class, $this->newInstance([ - '#[\inject\Inject] __construct' => function(Runnable $param) { /* Empty */ } + '#[Inject] __construct' => function(Runnable $param) { /* Empty */ } ])); $this->inject->get(Value::class); } @@ -113,9 +113,9 @@ public function injecting_unbound_into_constructor_via_method_annotation() { #[Test, Expect(class: ProvisionException::class, message: '/No bound value for type lang.Runnable/')] public function injecting_unbound_into_constructor_via_parameter_annotation() { $this->inject->bind(Value::class, $this->newInstance('{ - #[\inject\Inject] + #[Inject] public function __construct( - #[\inject\Inject] + #[Inject] \lang\Runnable $param ) { } }')); @@ -154,7 +154,7 @@ public function annotation_is_optional_multiple_parameters() { public function name_defaults_to_parameter() { $this->inject->bind(Value::class, $this->newInstance([ 'injected' => null, - '#[\inject\Inject] __construct' => function(AnnotationsTest $test, Storage $storage, string $name) { + '#[Inject] __construct' => function(AnnotationsTest $test, Storage $storage, string $name) { $this->injected= [$test, $storage, $name]; } ])); diff --git a/src/test/php/inject/unittest/AnnotationsTest.class.php b/src/test/php/inject/unittest/AnnotationsTest.class.php index 1c8e136..43df720 100755 --- a/src/test/php/inject/unittest/AnnotationsTest.class.php +++ b/src/test/php/inject/unittest/AnnotationsTest.class.php @@ -8,7 +8,6 @@ abstract class AnnotationsTest { protected $inject; - protected $id= 0; #[Before] public function inject() { @@ -27,7 +26,7 @@ public function inject() { */ protected function newInstance($definition) { return ClassLoader::defineClass( - 'inject.unittest.fixture.AnnotationsTest_'.($this->id++), + 'inject.AnnotationsTest_'.uniqid(), Value::class, [], $definition diff --git a/src/test/php/inject/unittest/NewInstanceTest.class.php b/src/test/php/inject/unittest/NewInstanceTest.class.php index 6e6d200..f7b1da1 100755 --- a/src/test/php/inject/unittest/NewInstanceTest.class.php +++ b/src/test/php/inject/unittest/NewInstanceTest.class.php @@ -14,11 +14,11 @@ class NewInstanceTest { * Creates a unique and new fixture subclass with the given definition * * @param [:var] $definition - * @return inject.unittest.fixture.Storage + * @return inject.unittest.fixture.Fixture */ protected function newFixture($definition) { return ClassLoader::defineClass( - 'inject.unittest.fixture.T'.uniqid(), + 'inject.NewInstanceTest_'.uniqid(), 'inject.unittest.fixture.Fixture', [], $definition @@ -50,7 +50,7 @@ public function storage() { public function newInstance_performs_injection() { $inject= (new Injector())->bind(Storage::class, $this->storage); $fixture= $this->newFixture([ - '#[\inject\Inject] __construct' => function(Storage $param) { $this->injected= $param; } + '#[Inject] __construct' => function(Storage $param) { $this->injected= $param; } ]); Assert::equals($this->storage, $inject->newInstance($fixture)->injected); @@ -60,7 +60,7 @@ public function newInstance_performs_injection() { public function newInstance_performs_named_injection_using_array_form() { $inject= (new Injector())->bind(Storage::class, $this->storage, 'test'); $fixture= $this->newFixture([ - '#[\inject\Inject(name: "test")] __construct' => function(Storage $param) { $this->injected= $param; } + '#[Inject(name: "test")] __construct' => function(Storage $param) { $this->injected= $param; } ]); Assert::equals($this->storage, $inject->newInstance($fixture)->injected); @@ -70,7 +70,7 @@ public function newInstance_performs_named_injection_using_array_form() { public function newInstance_performs_named_injection_using_string_form() { $inject= (new Injector())->bind(Storage::class, $this->storage, 'test'); $fixture= $this->newFixture([ - '#[\inject\Inject("test")] __construct' => function(Storage $param) { $this->injected= $param; } + '#[Inject("test")] __construct' => function(Storage $param) { $this->injected= $param; } ]); Assert::equals($this->storage, $inject->newInstance($fixture)->injected); @@ -112,7 +112,7 @@ public function newInstance_performs_partial_injection_with_optional_parameter() $inject= new Injector(); $inject->bind(Storage::class, $this->storage); $fixture= $this->newFixture([ - '#[\inject\Inject] __construct' => function(Storage $param, $verify= true) { $this->injected= [$param, $verify]; } + '#[Inject] __construct' => function(Storage $param, $verify= true) { $this->injected= [$param, $verify]; } ]); Assert::equals([$this->storage, true], $inject->newInstance($fixture)->injected); @@ -121,7 +121,7 @@ public function newInstance_performs_partial_injection_with_optional_parameter() #[Test, Expect(class: CannotInstantiate::class, message: '/Cannot instantiate .+/')] public function newInstance_catches_cannot_instantiate_when_creating_class_instances() { $this->newInstance(new Injector(), $this->newFixture('{ - #[\inject\Inject] + #[Inject] private function __construct() { } }')); } @@ -129,7 +129,7 @@ private function __construct() { } #[Test, Expect(class: ProvisionException::class, message: '/No bound value for type string named "endpoint"/')] public function newInstance_throws_when_value_for_required_parameter_not_found() { $this->newInstance(new Injector(), $this->newFixture('{ - #[\inject\Inject(type: "string", name: "endpoint")] + #[Inject(type: "string", name: "endpoint")] public function __construct($uri) { } }')); } From a2db1acf479fc733b1b7a8160d2ec72f9f23661e Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 30 Jul 2023 09:20:36 +0200 Subject: [PATCH 4/4] Consistently use fully qualified names --- .../php/inject/unittest/AnnotatedConstructorTest.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php b/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php index 4ad77c8..ac86eaa 100755 --- a/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php +++ b/src/test/php/inject/unittest/AnnotatedConstructorTest.class.php @@ -74,7 +74,7 @@ public function with_inject_parameter_annotations() { public function __construct( #[Inject] - unittest\AnnotationsTest $test, + \inject\unittest\AnnotationsTest $test, #[Inject(name: "EUR")] \util\Currency $cur ) { @@ -91,8 +91,8 @@ public function with_inject_annotation_and_inject_parameter_annotations() { #[Inject] public function __construct( - unittest\AnnotationsTest $test, - unittest\fixture\Storage $storage, + \inject\unittest\AnnotationsTest $test, + \inject\unittest\fixture\Storage $storage, #[Inject(name: "name", type: "string")] $name ) {