upd: database.core.Repo (made it simpler, 2 args instead of an array of 2 strings...)

This commit is contained in:
xdrm-brackets 2017-11-26 11:41:41 +01:00
parent acb879d472
commit e10382155a
1 changed files with 12 additions and 12 deletions

View File

@ -26,20 +26,20 @@
public static function request(Array $path=null){ public static function request(String $repo=null, String $method=null){
/* (1) Check arguments /* (1) Check arguments
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Check @path */ /* (1) Check @repo */
if( !is_array($path) || count($path) != 2 ) if( !is_string($repo) || strlen($repo) < 1 )
throw new \Exception("@path is not an array with 2 elements"); throw new \Exception("@repo is not a non-empty string");
/* (2) Deep check @path */ /* (2) Check @method */
if( !is_string($path[0]) || !is_string($path[1]) ) if( !is_string($method) || strlen($method) < 1 )
throw new \Exception("@path elements must be 2 strings"); throw new \Exception("@method is not a non-empty string");
/* (3) Check class path */ /* (3) Check class path */
$class_path = "\\database\\repo\\".$path[0]; $class_path = "\\database\\repo\\$repo";
if( !\class_exists($class_path) ) if( !\class_exists($class_path) )
throw new \Exception("Repo class '$class_path' cannot be found"); throw new \Exception("Repo class '$class_path' cannot be found");
@ -51,7 +51,7 @@
$instance = new $class_path(); $instance = new $class_path();
/* (2) Check extends Repo_i */ /* (2) Check extends Repo_i */
if( !( $instance instanceof Repo_i) ) if( !( $instance instanceof Repo_i ) )
throw new \Exception("Repo class '$class_path' must extends Repo_i"); throw new \Exception("Repo class '$class_path' must extends Repo_i");
/* (3) Bind pdo instance */ /* (3) Bind pdo instance */
@ -59,11 +59,11 @@
/* (3) Check if the method exists */ /* (3) Check if the method exists */
if( !\method_exists($instance, $path[1]) ) if( !\method_exists($instance, $method) )
throw new \Exception("Repo '${path[0]}' has no public method '{$path[1]}'"); throw new \Exception("Repo '$repo' has no public method '$method'");
/* (4) Fetch response (send arguments as well) */ /* (4) Fetch response (send arguments as well) */
$response = call_user_func_array([$instance, $path[1]], array_slice(func_get_args(), 1)); $response = call_user_func_array([$instance, $method], array_slice(func_get_args(), 2));
/* (5) Call post-script */ /* (5) Call post-script */
$instance = null; $instance = null;