Skip to content

Commit 265b8b2

Browse files
committed
Updated controller() method. Added camelCase to snake-case transform for auto generated methods.
1 parent f1e4015 commit 265b8b2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Router.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public function controller($route, $settings, $controller = null)
468468
}
469469

470470
$controller = str_replace(['\\', '.'], '/', $controller);
471+
$controller = trim(preg_replace('/'.$this->paths['controllers'].'/i', '', $controller, 1), '/');
471472
$controllerFile = realpath(
472473
rtrim($this->paths['controllers'], '/') . '/' . $controller . '.php'
473474
);
@@ -493,14 +494,15 @@ public function controller($route, $settings, $controller = null)
493494
}
494495
}
495496

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

501503
$value = ($methodVar === $this->mainMethod ? $route : $route.'/'.$methodVar);
502504
$this->{$method}(
503-
($value.str_repeat('/{a}', $reqiredParam).str_repeat('/{a?}', $totalParam-$reqiredParam)),
505+
($value.str_repeat('/:any', $reqiredParam).str_repeat('/:any?', $totalParam-$reqiredParam)),
504506
$settings,
505507
($controller . '@' . $methodName)
506508
);

0 commit comments

Comments
 (0)