Skip to content

Commit 17c0416

Browse files
authored
Revert "[11.x] fix: allows injection using multiple interfaces with the same …" (#53955)
This reverts commit a306193.
1 parent f349abb commit 17c0416

File tree

2 files changed

+5
-111
lines changed

2 files changed

+5
-111
lines changed

src/Illuminate/Routing/ResolvesRouteDependencies.php

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
namespace Illuminate\Routing;
44

55
use Illuminate\Container\Util;
6-
use Illuminate\Contracts\Container\BindingResolutionException;
76
use Illuminate\Support\Arr;
87
use Illuminate\Support\Reflector;
98
use ReflectionClass;
10-
use ReflectionException;
119
use ReflectionFunctionAbstract;
1210
use ReflectionMethod;
1311
use ReflectionParameter;
@@ -49,24 +47,15 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA
4947

5048
$skippableValue = new stdClass;
5149

52-
$resolvedInterfaces = [];
53-
5450
foreach ($reflector->getParameters() as $key => $parameter) {
55-
$className = Reflector::getParameterClassName($parameter);
56-
57-
$instance = $this->transformDependency($parameter, $parameters, $className, $skippableValue, $resolvedInterfaces);
58-
59-
if ($instance !== $skippableValue &&
60-
! $this->alreadyInResolvedInterfaces($className, $resolvedInterfaces)) {
61-
$resolvedInterfaces[] = $className;
62-
}
51+
$instance = $this->transformDependency($parameter, $parameters, $skippableValue);
6352

6453
if ($instance !== $skippableValue) {
6554
$instanceCount++;
6655

6756
$this->spliceIntoParameters($parameters, $key, $instance);
6857
} elseif (! isset($values[$key - $instanceCount]) &&
69-
$parameter->isDefaultValueAvailable()) {
58+
$parameter->isDefaultValueAvailable()) {
7059
$this->spliceIntoParameters($parameters, $key, $parameter->getDefaultValue());
7160
}
7261

@@ -79,27 +68,18 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA
7968
/**
8069
* Attempt to transform the given parameter into a class instance.
8170
*
82-
* @param ReflectionParameter $parameter
71+
* @param \ReflectionParameter $parameter
8372
* @param array $parameters
84-
* @param string $className
8573
* @param object $skippableValue
86-
* @param $resolvedInterfaces
8774
* @return mixed
88-
*
89-
* @throws BindingResolutionException
90-
* @throws ReflectionException
9175
*/
92-
protected function transformDependency(ReflectionParameter $parameter, $parameters, $className, object $skippableValue, $resolvedInterfaces)
76+
protected function transformDependency(ReflectionParameter $parameter, $parameters, $skippableValue)
9377
{
9478
if ($attribute = Util::getContextualAttributeFromDependency($parameter)) {
9579
return $this->container->resolveFromAttribute($attribute);
9680
}
9781

98-
if ($this->isSimilarConcreteToExistingParameterButDifferentInterface(
99-
$className, $parameters, $resolvedInterfaces
100-
)) {
101-
return $this->container->make($className);
102-
}
82+
$className = Reflector::getParameterClassName($parameter);
10383

10484
// If the parameter has a type-hinted class, we will check to see if it is already in
10585
// the list of parameters. If it is we will just skip it as it is probably a model
@@ -115,24 +95,6 @@ protected function transformDependency(ReflectionParameter $parameter, $paramete
11595
return $skippableValue;
11696
}
11797

118-
/**
119-
* Determines if an instance of the given class is already in the parameters, but the route is type-hinting another interface that hasn't yet been resolved.
120-
*
121-
* @param string $className
122-
* @param array $parameters
123-
* @param array $resolvedInterfaces
124-
* @return bool
125-
*/
126-
protected function isSimilarConcreteToExistingParameterButDifferentInterface($className, array $parameters, array $resolvedInterfaces)
127-
{
128-
// See: https://github.com/laravel/framework/pull/53275
129-
return $className &&
130-
$this->alreadyInParameters($className, $parameters) &&
131-
interface_exists($className) &&
132-
! $this->alreadyInResolvedInterfaces($className, $resolvedInterfaces) &&
133-
(new ReflectionClass($className))->isInterface();
134-
}
135-
13698
/**
13799
* Determine if an object of the given class is in a list of parameters.
138100
*
@@ -145,22 +107,6 @@ protected function alreadyInParameters($class, array $parameters)
145107
return ! is_null(Arr::first($parameters, fn ($value) => $value instanceof $class));
146108
}
147109

148-
/**
149-
* Determine if the given class name is already in the list of resolved interfaces.
150-
*
151-
* @param string|null $class
152-
* @param array $resolvedInterfaces
153-
* @return bool
154-
*/
155-
protected function alreadyInResolvedInterfaces($class, array $resolvedInterfaces)
156-
{
157-
if (! is_null($class)) {
158-
return in_array($class, $resolvedInterfaces);
159-
}
160-
161-
return false;
162-
}
163-
164110
/**
165111
* Splice the given value into the parameter list.
166112
*

tests/Routing/RouteDependencyInjectionTest.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)