Skip to content

Commit 24425c6

Browse files
committed
Merge remote-tracking branch 'origin/7.x' into 7.x
2 parents 50bc2eb + 6f2b0b7 commit 24425c6

File tree

12 files changed

+88
-28
lines changed

12 files changed

+88
-28
lines changed

src/Illuminate/Auth/Access/Gate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ protected function callbackAllowsGuests($callback)
450450
*/
451451
protected function parameterAllowsGuests($parameter)
452452
{
453-
return ($parameter->getClass() && $parameter->allowsNull()) ||
453+
return ($parameter->hasType() && $parameter->allowsNull()) ||
454454
($parameter->isDefaultValueAvailable() && is_null($parameter->getDefaultValue()));
455455
}
456456

src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Routing\BindingRegistrar;
99
use Illuminate\Contracts\Routing\UrlRoutable;
1010
use Illuminate\Support\Arr;
11+
use Illuminate\Support\Reflector;
1112
use Illuminate\Support\Str;
1213
use ReflectionClass;
1314
use ReflectionFunction;
@@ -204,9 +205,9 @@ protected function resolveImplicitBindingIfPossible($key, $value, $callbackParam
204205
continue;
205206
}
206207

207-
$instance = $parameter->getClass()->newInstance();
208+
$className = Reflector::getParameterClassName($parameter);
208209

209-
if (! $model = $instance->resolveRouteBinding($value)) {
210+
if (is_null($model = (new $className)->resolveRouteBinding($value))) {
210211
throw new AccessDeniedHttpException;
211212
}
212213

@@ -225,8 +226,8 @@ protected function resolveImplicitBindingIfPossible($key, $value, $callbackParam
225226
*/
226227
protected function isImplicitlyBindable($key, $parameter)
227228
{
228-
return $parameter->name === $key && $parameter->getClass() &&
229-
$parameter->getClass()->isSubclassOf(UrlRoutable::class);
229+
return $parameter->getName() === $key &&
230+
Reflector::isParameterSubclassOf($parameter, UrlRoutable::class);
230231
}
231232

232233
/**

src/Illuminate/Container/BoundMethod.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,20 @@ protected static function getCallReflector($callback)
158158
protected static function addDependencyForCallParameter($container, $parameter,
159159
array &$parameters, &$dependencies)
160160
{
161-
if (array_key_exists($parameter->name, $parameters)) {
162-
$dependencies[] = $parameters[$parameter->name];
161+
if (array_key_exists($parameter->getName(), $parameters)) {
162+
$paramName = $parameter->getName();
163163

164-
unset($parameters[$parameter->name]);
165-
} elseif ($parameter->getClass() && array_key_exists($parameter->getClass()->name, $parameters)) {
166-
$dependencies[] = $parameters[$parameter->getClass()->name];
164+
$dependencies[] = $parameters[$paramName];
167165

168-
unset($parameters[$parameter->getClass()->name]);
169-
} elseif ($parameter->getClass()) {
170-
$dependencies[] = $container->make($parameter->getClass()->name);
166+
unset($parameters[$paramName]);
167+
} elseif (! is_null($className = Util::getParameterClassName($parameter))) {
168+
if (array_key_exists($className, $parameters)) {
169+
$dependencies[] = $parameters[$className];
170+
171+
unset($parameters[$className]);
172+
} else {
173+
$dependencies[] = $container->make($className);
174+
}
171175
} elseif ($parameter->isDefaultValueAvailable()) {
172176
$dependencies[] = $parameter->getDefaultValue();
173177
} elseif (! $parameter->isOptional() && ! array_key_exists($parameter->name, $parameters)) {

src/Illuminate/Container/Container.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ public function build($concrete)
848848
/**
849849
* Resolve all of the dependencies from the ReflectionParameters.
850850
*
851-
* @param array $dependencies
851+
* @param \ReflectionParameter[] $dependencies
852852
* @return array
853853
*
854854
* @throws \Illuminate\Contracts\Container\BindingResolutionException
@@ -870,7 +870,7 @@ protected function resolveDependencies(array $dependencies)
870870
// If the class is null, it means the dependency is a string or some other
871871
// primitive type which we can not resolve since it is not a class and
872872
// we will just bomb out with an error since we have no-where to go.
873-
$result = is_null($dependency->getClass())
873+
$result = is_null(Util::getParameterClassName($dependency))
874874
? $this->resolvePrimitive($dependency)
875875
: $this->resolveClass($dependency);
876876

@@ -928,7 +928,7 @@ protected function getLastParameterOverride()
928928
*/
929929
protected function resolvePrimitive(ReflectionParameter $parameter)
930930
{
931-
if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) {
931+
if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->getName()))) {
932932
return $concrete instanceof Closure ? $concrete($this) : $concrete;
933933
}
934934

@@ -952,7 +952,7 @@ protected function resolveClass(ReflectionParameter $parameter)
952952
try {
953953
return $parameter->isVariadic()
954954
? $this->resolveVariadicClass($parameter)
955-
: $this->make($parameter->getClass()->name);
955+
: $this->make(Util::getParameterClassName($parameter));
956956
}
957957

958958
// If we can not resolve the class instance, we will check to see if the value

src/Illuminate/Container/Util.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ public static function unwrapIfClosure($value)
3535
{
3636
return $value instanceof Closure ? $value() : $value;
3737
}
38+
39+
/**
40+
* Get the class name of the given parameter's type, if possible.
41+
*
42+
* From Reflector::getParameterClassName() in Illuminate\Support.
43+
*
44+
* @param \ReflectionParameter $parameter
45+
* @return string|null
46+
*/
47+
public static function getParameterClassName($parameter)
48+
{
49+
$type = $parameter->getType();
50+
51+
return ($type && ! $type->isBuiltin()) ? $type->getName() : null;
52+
}
3853
}

src/Illuminate/Foundation/Console/ClosureCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
4646
$parameters = [];
4747

4848
foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) {
49-
if (isset($inputs[$parameter->name])) {
50-
$parameters[$parameter->name] = $inputs[$parameter->name];
49+
if (isset($inputs[$parameter->getName()])) {
50+
$parameters[$parameter->getName()] = $inputs[$parameter->getName()];
5151
}
5252
}
5353

src/Illuminate/Foundation/Events/DiscoverEvents.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Foundation\Events;
44

5+
use Illuminate\Support\Reflector;
56
use Illuminate\Support\Str;
67
use ReflectionClass;
78
use ReflectionException;
@@ -58,7 +59,7 @@ protected static function getListenerEvents($listeners, $basePath)
5859
}
5960

6061
$listenerEvents[$listener->name.'@'.$method->name] =
61-
optional($method->getParameters()[0]->getClass())->name;
62+
Reflector::getParameterClassName($method->getParameters()[0]);
6263
}
6364
}
6465

src/Illuminate/Routing/ImplicitRouteBinding.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Contracts\Routing\UrlRoutable;
66
use Illuminate\Database\Eloquent\ModelNotFoundException;
7+
use Illuminate\Support\Reflector;
78
use Illuminate\Support\Str;
89

910
class ImplicitRouteBinding
@@ -22,7 +23,7 @@ public static function resolveForRoute($container, $route)
2223
$parameters = $route->parameters();
2324

2425
foreach ($route->signatureParameters(UrlRoutable::class) as $parameter) {
25-
if (! $parameterName = static::getParameterName($parameter->name, $parameters)) {
26+
if (! $parameterName = static::getParameterName($parameter->getName(), $parameters)) {
2627
continue;
2728
}
2829

@@ -32,7 +33,7 @@ public static function resolveForRoute($container, $route)
3233
continue;
3334
}
3435

35-
$instance = $container->make($parameter->getClass()->name);
36+
$instance = $container->make(Reflector::getParameterClassName($parameter));
3637

3738
$parent = $route->parentOfParameter($parameterName);
3839

src/Illuminate/Routing/RouteDependencyResolverTrait.php

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

55
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Reflector;
67
use ReflectionFunctionAbstract;
78
use ReflectionMethod;
89
use ReflectionParameter;
@@ -69,15 +70,13 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA
6970
*/
7071
protected function transformDependency(ReflectionParameter $parameter, $parameters, $skippableValue)
7172
{
72-
$class = $parameter->getClass();
73+
$className = Reflector::getParameterClassName($parameter);
7374

7475
// If the parameter has a type-hinted class, we will check to see if it is already in
7576
// the list of parameters. If it is we will just skip it as it is probably a model
7677
// binding and we do not want to mess with those; otherwise, we resolve it here.
77-
if ($class && ! $this->alreadyInParameters($class->name, $parameters)) {
78-
return $parameter->isDefaultValueAvailable()
79-
? null
80-
: $this->container->make($class->name);
78+
if ($className && ! $this->alreadyInParameters($className, $parameters)) {
79+
return $parameter->isDefaultValueAvailable() ? null : $this->container->make($className);
8180
}
8281

8382
return $skippableValue;

src/Illuminate/Routing/RouteSignatureParameters.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Routing;
44

5+
use Illuminate\Support\Reflector;
56
use Illuminate\Support\Str;
67
use ReflectionFunction;
78
use ReflectionMethod;
@@ -22,7 +23,7 @@ public static function fromAction(array $action, $subClass = null)
2223
: (new ReflectionFunction($action['uses']))->getParameters();
2324

2425
return is_null($subClass) ? $parameters : array_filter($parameters, function ($p) use ($subClass) {
25-
return $p->getClass() && $p->getClass()->isSubclassOf($subClass);
26+
return Reflector::isParameterSubclassOf($p, $subClass);
2627
});
2728
}
2829

0 commit comments

Comments
 (0)