mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
[FEATURE] Added class + method loading to IClassLoader.
This commit is contained in:
@@ -22,6 +22,18 @@ class ClassLoader implements IClassLoader
|
||||
return new $class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when loading class method
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return object
|
||||
*/
|
||||
public function loadClassMethod($class, string $method, array $parameters)
|
||||
{
|
||||
return call_user_func_array([$class, $method], array_values($parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load closure
|
||||
*
|
||||
|
||||
@@ -12,6 +12,15 @@ interface IClassLoader
|
||||
*/
|
||||
public function loadClass(string $class);
|
||||
|
||||
/**
|
||||
* Called when loading class method
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return object
|
||||
*/
|
||||
public function loadClassMethod($class, string $method, array $parameters);
|
||||
|
||||
/**
|
||||
* Called when loading method
|
||||
*
|
||||
@@ -21,4 +30,4 @@ interface IClassLoader
|
||||
*/
|
||||
public function loadClosure(Callable $closure, array $parameters);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -97,9 +97,9 @@ abstract class Route implements IRoute
|
||||
throw new ClassNotFoundHttpException($className, $method, sprintf('Method "%s" does not exist in class "%s"', $method, $className), 404, null);
|
||||
}
|
||||
|
||||
$router->debug('Executing callback');
|
||||
$router->debug('Executing callback %s -> %s', $className, $method);
|
||||
|
||||
return call_user_func_array([$class, $method], $parameters);
|
||||
return $router->getClassLoader()->loadClassMethod($class, $method, $parameters);
|
||||
}
|
||||
|
||||
protected function parseParameters($route, $url, $parameterRegex = null): ?array
|
||||
|
||||
Reference in New Issue
Block a user