2018-02-17 17:18:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**************************
|
|
|
|
* Repo *
|
|
|
|
* 24-11-2017 *
|
|
|
|
***************************
|
|
|
|
* Designed & Developed by *
|
|
|
|
* xdrm-brackets *
|
|
|
|
***************************
|
|
|
|
* https://xdrm.io/ *
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
namespace database\core;
|
|
|
|
|
2018-03-08 19:09:02 +00:00
|
|
|
use database\core\PDOWrapper\PDOWrapper;
|
2018-02-17 17:18:58 +00:00
|
|
|
use \error\core\Error;
|
|
|
|
use \error\core\Err;
|
|
|
|
|
|
|
|
class Repo{
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Driver
|
|
|
|
---------------------------------------------------------*/
|
2018-03-08 19:09:02 +00:00
|
|
|
/**
|
|
|
|
* @var DatabaseDriver
|
|
|
|
*/
|
2018-02-17 17:18:58 +00:00
|
|
|
private static $driver = null;
|
|
|
|
|
|
|
|
public static function setDriver(DatabaseDriver $driver){ self::$driver = $driver; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-27 19:41:36 +00:00
|
|
|
public static function getRepo(String $repo=null) : Repo_i{
|
2018-02-17 17:18:58 +00:00
|
|
|
|
|
|
|
/* (1) Check arguments
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Check @repo */
|
|
|
|
if( !is_string($repo) || strlen($repo) < 1 )
|
|
|
|
throw new \Exception("@repo is not a non-empty string");
|
|
|
|
|
2018-02-27 19:41:36 +00:00
|
|
|
/* (1) Check class path */
|
2018-02-17 17:18:58 +00:00
|
|
|
$class_path = "\\database\\repo\\$repo";
|
|
|
|
|
|
|
|
if( !\class_exists($class_path) )
|
|
|
|
throw new \Exception("Repo class '$class_path' cannot be found");
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Call the method
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Create the instance (pre-script) */
|
|
|
|
$instance = new $class_path();
|
|
|
|
|
|
|
|
/* (2) Check extends Repo_i */
|
|
|
|
if( !( $instance instanceof Repo_i ) )
|
|
|
|
throw new \Exception("Repo class '$class_path' must extends Repo_i");
|
|
|
|
|
|
|
|
/* (3) Bind pdo instance */
|
|
|
|
\call_user_func([$instance, 'setPDO'], self::$driver->pdo());
|
|
|
|
|
|
|
|
|
2018-02-27 19:41:36 +00:00
|
|
|
return $instance;
|
2018-02-17 17:18:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 19:09:02 +00:00
|
|
|
public static function enableStacking(){
|
|
|
|
static::$driver->enableStacking();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function flushStack(){
|
|
|
|
static::$driver->flushStack();
|
|
|
|
}
|
|
|
|
|
2018-02-17 17:18:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|