Skip to content

Commit

Permalink
- added check for using interface instead of implementation;
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTray committed Dec 22, 2021
1 parent 5fdc88e commit 1806977
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 1806977

Please sign in to comment.