mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 19:02:19 +00:00
[FEATURE] Added class + method loading to IClassLoader.
This commit is contained in:
@@ -22,6 +22,18 @@ class ClassLoader implements IClassLoader
|
|||||||
return new $class();
|
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
|
* Load closure
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -12,6 +12,15 @@ interface IClassLoader
|
|||||||
*/
|
*/
|
||||||
public function loadClass(string $class);
|
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
|
* Called when loading method
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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);
|
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
|
protected function parseParameters($route, $url, $parameterRegex = null): ?array
|
||||||
|
|||||||
@@ -7,8 +7,20 @@ class CustomClassLoader implements \Pecee\SimpleRouter\ClassLoader\IClassLoader
|
|||||||
return new DummyController();
|
return new DummyController();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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], ['result' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
public function loadClosure(callable $closure, array $parameters)
|
public function loadClosure(callable $closure, array $parameters)
|
||||||
{
|
{
|
||||||
return \call_user_func_array($closure, ['result' => true]);
|
return call_user_func_array($closure, ['result' => true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user