Skip to content

Commit f9a4b3f

Browse files
committed
- fixes the ReflectionParameter::getClass() deprecation (PHP 8)
- uses the extended container interface - visibility lowered for some methods
1 parent 9d82412 commit f9a4b3f

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

DIReflector.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
use ReflectionParameter;
2222
use Throwable;
2323

24-
final class DIReflector
24+
class DIReflector
2525
{
26-
public function newInstance(DIContainer $container, string $class, array $arguments): object
26+
public function newInstance(DIContainerInterface $container, string $class, array $arguments): object
2727
{
2828
$dependency = new ReflectionClass($class);
2929
$constructor = $dependency->getConstructor();
@@ -44,14 +44,14 @@ public function newInstance(DIContainer $container, string $class, array $argume
4444
}
4545

4646
/**
47-
* @param DIContainer $container
47+
* @param DIContainerInterface $container
4848
* @param ReflectionFunction | ReflectionMethod $method
4949
* @param array $arguments
5050
*
5151
* @return array
5252
*/
5353
public function processMethodArguments(
54-
DIContainer $container,
54+
DIContainerInterface $container,
5555
ReflectionFunctionAbstract $method,
5656
array $arguments
5757
): array {
@@ -102,9 +102,12 @@ public function newMethodFromCallable(callable $callable): ReflectionFunctionAbs
102102
}
103103
}
104104

105-
private function getFromParameterType(DIContainer $container, ReflectionParameter $parameter, array $arguments)
106-
{
107-
if (!$dependency = $parameter->getClass()) {
105+
protected function getFromParameterType(
106+
DIContainerInterface $container,
107+
ReflectionParameter $parameter,
108+
array $arguments
109+
) {
110+
if (!$class = $parameter->getType()) {
108111
return $arguments[$parameter->getPosition()]
109112
?? $this->getFromParameter($container, $parameter);
110113
}
@@ -118,13 +121,13 @@ private function getFromParameterType(DIContainer $container, ReflectionParamete
118121
return $parameter->getDefaultValue();
119122
}
120123

121-
return $container->new($dependency->name);
124+
return $container->new($class);
122125
}
123126

124-
private function getFromParameter(DIContainer $container, ReflectionParameter $parameter)
127+
protected function getFromParameter(DIContainerInterface $container, ReflectionParameter $parameter)
125128
{
126129
$storage = $container->getStorage();
127-
$name = ($parameter->getClass() ?: $parameter)->name;
130+
$name = ($parameter->getType() ?? $parameter)->getName();
128131

129132
if (isset($storage[DIContainer::BINDINGS][$name])) {
130133
$name = $storage[DIContainer::BINDINGS][$name];

0 commit comments

Comments
 (0)