Skip to content

Commit

Permalink
fix route model binding on cached closure routes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 24, 2020
1 parent eea6091 commit eb3e262
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/Illuminate/Routing/ImplicitRouteBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static function resolveForRoute($container, $route)
$instance = $container->make(Reflector::getParameterClassName($parameter));

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

if ($parent instanceof UrlRoutable && in_array($parameterName, array_keys($route->bindingFields()))) {
if (! $model = $parent->resolveChildRouteBinding(
$parameterName, $parameterValue, $route->bindingFieldFor($parameterName)
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ protected function runCallable()
*/
protected function isSerializedClosure()
{
return is_string($this->action['uses']) &&
Str::startsWith($this->action['uses'], 'C:32:"Opis\\Closure\\SerializableClosure') !== false;
return RouteAction::containsSerializedClosure($this->action);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Routing/RouteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,16 @@ protected static function makeInvokable($action)

return $action.'@__invoke';
}

/**
* Determine if the given array actions contains a serialized Closure.
*
* @param array $action
* @return bool
*/
public static function containsSerializedClosure(array $action)
{
return is_string($action['uses']) &&
Str::startsWith($action['uses'], 'C:32:"Opis\\Closure\\SerializableClosure') !== false;
}
}
10 changes: 7 additions & 3 deletions src/Illuminate/Routing/RouteSignatureParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class RouteSignatureParameters
*/
public static function fromAction(array $action, $subClass = null)
{
$parameters = is_string($action['uses'])
? static::fromClassMethodString($action['uses'])
: (new ReflectionFunction($action['uses']))->getParameters();
$callback = RouteAction::containsSerializedClosure($action)
? unserialize($action['uses'])->getClosure()
: $action['uses'];

$parameters = is_string($callback)
? static::fromClassMethodString($callback)
: (new ReflectionFunction($callback))->getParameters();

return is_null($subClass) ? $parameters : array_filter($parameters, function ($p) use ($subClass) {
return Reflector::isParameterSubclassOf($p, $subClass);
Expand Down

0 comments on commit eb3e262

Please sign in to comment.