Skip to content

Commit

Permalink
Updated controller() method. Added camelCase to snake-case transform …
Browse files Browse the repository at this point in the history
…for auto generated methods.
  • Loading branch information
izniburak committed Jul 2, 2019
1 parent f1e4015 commit 265b8b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ public function controller($route, $settings, $controller = null)
}

$controller = str_replace(['\\', '.'], '/', $controller);
$controller = trim(preg_replace('/'.$this->paths['controllers'].'/i', '', $controller, 1), '/');
$controllerFile = realpath(
rtrim($this->paths['controllers'], '/') . '/' . $controller . '.php'
);
Expand All @@ -493,14 +494,15 @@ public function controller($route, $settings, $controller = null)
}
}

$methodVar = lcfirst(str_replace($method, '', $methodName));
$methodVar = lcfirst(preg_replace('/'.$method.'/i', '', $methodName, 1));
$methodVar = strtolower(preg_replace('%([a-z]|[0-9])([A-Z])%', '\1-\2', $methodVar));
$r = new ReflectionMethod($this->namespaces['controllers'] . $controller, $methodName);
$reqiredParam = $r->getNumberOfRequiredParameters();
$totalParam = $r->getNumberOfParameters();

$value = ($methodVar === $this->mainMethod ? $route : $route.'/'.$methodVar);
$this->{$method}(
($value.str_repeat('/{a}', $reqiredParam).str_repeat('/{a?}', $totalParam-$reqiredParam)),
($value.str_repeat('/:any', $reqiredParam).str_repeat('/:any?', $totalParam-$reqiredParam)),
$settings,
($controller . '@' . $methodName)
);
Expand Down

0 comments on commit 265b8b2

Please sign in to comment.