Skip to content

Commit

Permalink
Optimize implementation bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jul 21, 2024
1 parent fb09473 commit ed38bea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/php/inject/Implementations.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/** @test inject.unittest.ImplementationsTest */
#[Generic(self: 'T')]
class Implementations {
class Implementations implements Binding {
private $inject, $bindings;

/**
Expand Down Expand Up @@ -49,4 +49,24 @@ public function named(string $name) {

throw new ProvisionException('No implementation named "'.$name.'"');
}

/**
* Resolves this binding and returns the instance
*
* @param inject.Injector $injector
* @return var
*/
public function resolve($injector) {
return $this;
}

/**
* Returns a provider for this binding
*
* @param inject.Injector $injector
* @return inject.Provider<?>
*/
public function provider($injector) {
return $this;
}
}
2 changes: 1 addition & 1 deletion src/main/php/inject/Injector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function binding($type, $name= null) {
} else if ($t instanceof Nullable) {
return $this->binding($t->underlyingType(), $name);
} else if (self::$IMPLEMENTATIONS->isAssignableFrom($t)) {
return new InstanceBinding($this->implementations($t->genericArguments()[0]));
return $this->implementations($t->genericArguments()[0]);
} else if (self::$PROVIDER->isAssignableFrom($t)) {
$literal= $t->genericArguments()[0]->literal();
if ($binding= $this->bindings[$literal][$name] ?? null) {
Expand Down

0 comments on commit ed38bea

Please sign in to comment.