Skip to content

Commit

Permalink
Merge pull request #34 from RonasIT/dpankratov/version-update
Browse files Browse the repository at this point in the history
- added check for using interface instead of implementation;
  • Loading branch information
DenTray authored Dec 22, 2021
2 parents c87538f + 1806977 commit c49d9e9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Traits/GetDependenciesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace RonasIT\Support\AutoDoc\Traits;

use ReflectionMethod;
use ReflectionFunctionAbstract;
use ReflectionFunction;
use ReflectionParameter;
use Illuminate\Support\Arr;
use ReflectionFunctionAbstract;
use Illuminate\Container\Container;

trait GetDependenciesTrait
{
Expand Down Expand Up @@ -34,6 +37,17 @@ protected function transformDependency(ReflectionParameter $parameter)
return null;
}

return interface_exists($class->name) ? get_class(app($class->name)) : $class->name;
return interface_exists($class->name) ? $this->getClassByInterface($class->name) : $class->name;
}

protected function getClassByInterface($interfaceName)
{
$bindings = Container::getInstance()->getBindings();

$implementation = Arr::get($bindings, "{$interfaceName}.concrete");

$classFields = (new ReflectionFunction($implementation))->getStaticVariables();

return $classFields['concrete'];
}
}

0 comments on commit c49d9e9

Please sign in to comment.