Skip to content

Commit

Permalink
Added template annotations to getInstanceOfClass methods
Browse files Browse the repository at this point in the history
  • Loading branch information
olexiyk authored and mdio committed Jan 4, 2022
1 parent 8f6a3f9 commit 4e7165c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/rg/injektor/DependencyInjectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ protected function checkForInjectionLoop($className) {
}

/**
* @param string $fullClassName
* @template InstanceType
*
* @param class-string<InstanceType> $fullClassName
* @param array $constructorArguments
* @return object
*
* @return InstanceType
*/
public function getInstanceOfClass($fullClassName, array $constructorArguments = array()) {
$this->iterationDepth++;
Expand Down
15 changes: 9 additions & 6 deletions src/rg/injektor/FactoryDependencyInjectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ class FactoryDependencyInjectionContainer extends DependencyInjectionContainer {
public static $prefix = '';

/**
* @param string $className
* @template InstanceType
*
* @param class-string<InstanceType> $fullClassName
* @param array $constructorArguments
* @return object
*
* @return InstanceType
*/
public function getInstanceOfClass($className, array $constructorArguments = array()) {
$fullFactoryClassName = $this->getFullFactoryClassName($className);
$factoryClassName = $this->getFactoryClassName($className);
public function getInstanceOfClass($fullClassName, array $constructorArguments = array()) {
$fullFactoryClassName = $this->getFullFactoryClassName($fullClassName);
$factoryClassName = $this->getFactoryClassName($fullClassName);

if ($this->factoryClassExists($fullFactoryClassName, $factoryClassName)) {
return $fullFactoryClassName::getInstance($constructorArguments);
}

return parent::getInstanceOfClass($className, $constructorArguments);
return parent::getInstanceOfClass($fullClassName, $constructorArguments);
}

/**
Expand Down
19 changes: 11 additions & 8 deletions src/rg/injektor/FactoryOnlyDependencyInjectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
class FactoryOnlyDependencyInjectionContainer extends FactoryDependencyInjectionContainer {

/**
* @param string $className
* @template InstanceType
*
* @param class-string<InstanceType> $fullClassName
* @param array $constructorArguments
*
* @return InstanceType
* @throws InjectionException
* @return object
*/
public function getInstanceOfClass($className, array $constructorArguments = array()) {
$className = trim($className, '\\');
$classConfig = $this->config->getClassConfig($className);
$className = $this->getRealConfiguredClassName($classConfig, new \ReflectionClass($className));
$fullFactoryClassName = $this->getFullFactoryClassName($className);
$factoryClassName = $this->getFactoryClassName($className);
public function getInstanceOfClass($fullClassName, array $constructorArguments = array()) {
$fullClassName = trim($fullClassName, '\\');
$classConfig = $this->config->getClassConfig($fullClassName);
$fullClassName = $this->getRealConfiguredClassName($classConfig, new \ReflectionClass($fullClassName));
$fullFactoryClassName = $this->getFullFactoryClassName($fullClassName);
$factoryClassName = $this->getFactoryClassName($fullClassName);

if ($this->factoryClassExists($fullFactoryClassName, $factoryClassName)) {
return $fullFactoryClassName::getInstance($constructorArguments);
Expand Down

0 comments on commit 4e7165c

Please sign in to comment.