mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Development
- Fixed: only set default namespace on relative callbacks. - Fixed: default-namespace not being set when calling `SimpleRouter::resource`. - Minor optimisations.
This commit is contained in:
@@ -27,9 +27,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
*/
|
||||
public function loadMiddleware(Request $request)
|
||||
{
|
||||
if (count($this->getMiddlewares()) > 0) {
|
||||
$max = count($this->getMiddlewares());
|
||||
|
||||
$max = count($this->getMiddlewares());
|
||||
if ($max > 0) {
|
||||
|
||||
for ($i = 0; $i < $max; $i++) {
|
||||
|
||||
@@ -37,7 +37,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
|
||||
$middleware = $this->loadClass($middleware);
|
||||
|
||||
if (!($middleware instanceof IMiddleware)) {
|
||||
if (($middleware instanceof IMiddleware) === false) {
|
||||
throw new HttpException($middleware . ' must be instance of Middleware');
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
|
||||
public function matchRegex(Request $request, $url)
|
||||
{
|
||||
|
||||
/* Match on custom defined regular expression */
|
||||
|
||||
if ($this->regex === null) {
|
||||
|
||||
@@ -57,16 +57,21 @@ abstract class Route implements IRoute
|
||||
|
||||
public function renderRoute(Request $request)
|
||||
{
|
||||
if ($this->getCallback() !== null && is_callable($this->getCallback())) {
|
||||
$callback = $this->getCallback();
|
||||
|
||||
if ($callback !== null && is_callable($callback)) {
|
||||
|
||||
/* When the callback is a function */
|
||||
call_user_func_array($this->getCallback(), $this->getParameters());
|
||||
call_user_func_array($callback, $this->getParameters());
|
||||
|
||||
} else {
|
||||
|
||||
/* When the callback is a method */
|
||||
$controller = explode('@', $this->getCallback());
|
||||
$className = $this->getNamespace() . '\\' . $controller[0];
|
||||
$controller = explode('@', $callback);
|
||||
|
||||
$namespace = $this->getNamespace();
|
||||
|
||||
$className = ($namespace !== null) ? $namespace . '\\' . $controller[0] : $controller[0];
|
||||
|
||||
$class = $this->loadClass($className);
|
||||
$method = $controller[1];
|
||||
|
||||
Reference in New Issue
Block a user