Development

- Added dependency injection support.
- Added php-di composer dependency.
- Added `ClassLoader` class.
- Added `IClassLoader` interface.
- Added unit-tests for dependency injection.
- Updated documentation to reflect new features.
This commit is contained in:
Simon Sessingø
2018-03-29 21:16:02 +02:00
parent cca2f5cb88
commit af2ac6031d
17 changed files with 382 additions and 68 deletions
+3 -17
View File
@@ -57,21 +57,6 @@ abstract class Route implements IRoute
protected $originalParameters = [];
protected $middlewares = [];
/**
* Load class by name
* @param string $name
* @return mixed
* @throws NotFoundHttpException
*/
protected function loadClass($name)
{
if (class_exists($name) === false) {
throw new NotFoundHttpException(sprintf('Class "%s" does not exist', $name), 404);
}
return new $name();
}
/**
* Render route
*
@@ -107,7 +92,7 @@ abstract class Route implements IRoute
/* When the callback is a function */
return \call_user_func_array($callback, $parameters);
return $router->getClassLoader()->loadClosure($callback, $parameters);
}
/* When the callback is a class + method */
@@ -118,7 +103,8 @@ abstract class Route implements IRoute
$className = ($namespace !== null && $controller[0][0] !== '\\') ? $namespace . '\\' . $controller[0] : $controller[0];
$router->debug('Loading class %s', $className);
$class = $this->loadClass($className);
$class = $router->getClassLoader()->loadClass($className);
$method = $controller[1];
if (method_exists($class, $method) === false) {