Skip to content

Commit

Permalink
Update ControllerResolver.php
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinHoutevelts authored Mar 5, 2018
1 parent 8f7440a commit ddf8686
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Controller/ControllerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ protected function doGetArguments(Request $request, $controller, array $paramete
elseif ($param->getClass() && ($param->getClass()->name == RouteMatchInterface::class || is_subclass_of($param->getClass()->name, RouteMatchInterface::class))) {
$arguments[] = RouteMatch::createFromRequest($request);
}
elseif ($WmModelEnabled && $this->addModel($arguments, $attributes, $param)) {
// noop
}
elseif ($param->isDefaultValueAvailable()) {
$arguments[] = $param->getDefaultValue();
}
// Also check by WmModel typehint
elseif ($WmModelEnabled && $param->getClass()) {
foreach ($attributes as $key => $attribute) {
if ($this->isWmModel($attribute) && $this->isSubclass($attribute, $param->getClass()->name)) {
$arguments[] = $attribute;
// Remove from attributes so it can't give the same argument multiple times
unset($attributes[$key]);
}
}
}
else {
if (is_array($controller)) {
$repr = sprintf('%s::%s()', get_class($controller[0]), $controller[1]);
Expand Down Expand Up @@ -95,4 +88,22 @@ protected function isWmModel($object)
{
return is_object($object) && is_subclass_of($object, WmModelInterface::class);
}
}

private function addModel(&$arguments, &$attributes, \ReflectionParameter $param)
{
if (!$param->getClass()) {
return false;
}

foreach ($attributes as $key => $attribute) {
if ($this->isWmModel($attribute) && $this->isSubclass($attribute, $param->getClass()->name)) {
$arguments[] = $attribute;
// Remove from attributes so it can't give the same argument multiple times
unset($attributes[$key]);
return true;
}
}

return false;
}
}

0 comments on commit ddf8686

Please sign in to comment.