dbDriverInterface[$routeName])) { $this->dbDriverInterface[$routeName] = []; } if (!is_array($dbDriver)) { $dbDriver = [$dbDriver]; } foreach ($dbDriver as $item) { $this->dbDriverInterface[$routeName][] = $item; } return $this; } /** * @param $routeName * @param null $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForSelect($routeName, $table = null) { if (empty($table)) { $table = '\w+'; } return $this->addCustomRoute($routeName, '^select.*from\s+([`]?' . $table . '[`]?)\s'); } /** * @param $routeName * @param null $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForInsert($routeName, $table = null) { if (empty($table)) { $table = '\w+'; } return $this->addCustomRoute($routeName, '^insert\s+into\s+([`]?' . $table . '[`]?)\s+\('); } /** * @param $routeName * @param null $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForUpdate($routeName, $table = null) { if (empty($table)) { $table = '\w+'; } return $this->addCustomRoute($routeName, '^update\s+([`]?' . $table . '[`]?)\s+set'); } /** * @param $routeName * @param null $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForDelete($routeName, $table = null) { if (empty($table)) { $table = '\w+'; } return $this->addCustomRoute($routeName, '^delete\s+(from\s+)?([`]?' . $table . '[`]?)\s'); } /** * @param $routeName * @param $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForTable($routeName, $table) { $this->addRouteForRead($routeName, $table); $this->addRouteForWrite($routeName, $table); return $this; } /** * @param $routeName * @param null $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForWrite($routeName, $table = null) { $this->addRouteForInsert($routeName, $table); $this->addRouteForUpdate($routeName, $table); $this->addRouteForDelete($routeName, $table); return $this; } /** * @param $routeName * @param null $table * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForRead($routeName, $table = null) { return $this->addRouteForSelect($routeName, $table); } /** * @param $routeName * @param $field * @param $value * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addRouteForFilter($routeName, $field, $value) { return $this->addCustomRoute($routeName, "\\s`?$field`?\\s*=\\s*'?$value'?\s"); } /** * @param $routeName * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addDefaultRoute($routeName) { return $this->addCustomRoute($routeName, '.'); } /** * @param $routeName * @param $regEx * @return \ByJG\AnyDataset\Db\Route * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException */ public function addCustomRoute($routeName, $regEx) { if (!isset($this->dbDriverInterface[$routeName])) { throw new RouteNotFoundException("Invalid route $routeName"); } $this->routes[$regEx] = $routeName; return $this; } /** * @param $sql * @return DbDriverInterface * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function matchRoute($sql) { $sql = trim(strtolower(str_replace("\n", " ", $sql))) . ' '; foreach ($this->routes as $pattern => $routeName) { if (!preg_match("/$pattern/", $sql)) { continue; } $dbDriver = $this->dbDriverInterface[$routeName][rand(0, count($this->dbDriverInterface[$routeName])-1)]; if (is_string($dbDriver)) { return Factory::getDbRelationalInstance($dbDriver); } return $dbDriver; } throw new RouteNotMatchedException('Route not matched'); } /** * @param string $sql * @param null $params * @return \ByJG\AnyDataset\Core\GenericIterator * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function getIterator($sql, $params = null) { $dbDriver = $this->matchRoute($sql); return $dbDriver->getIterator($sql, $params); } /** * @param $sql * @param null $array * @return mixed * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function getScalar($sql, $array = null) { $dbDriver = $this->matchRoute($sql); return $dbDriver->getScalar($sql, $array); } /** * @param $tablename * @throws NotImplementedException */ public function getAllFields($tablename) { throw new NotImplementedException('Feature not available'); } /** * @param $sql * @param null $array * @return mixed * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function execute($sql, $array = null) { $dbDriver = $this->matchRoute($sql); return $dbDriver->execute($sql, $array); } /** * @throws NotImplementedException */ public function beginTransaction() { throw new NotImplementedException('Feature not available'); } /** * @throws NotImplementedException */ public function commitTransaction() { throw new NotImplementedException('Feature not available'); } /** * @throws NotImplementedException */ public function rollbackTransaction() { throw new NotImplementedException('Feature not available'); } /** * @return \PDO|void * @throws NotImplementedException */ public function getDbConnection() { throw new NotImplementedException('Feature not available'); } /** * @param $name * @param $value * @throws NotImplementedException */ public function setAttribute($name, $value) { throw new NotImplementedException('Feature not available'); } /** * @param $name * @throws NotImplementedException */ public function getAttribute($name) { throw new NotImplementedException('Feature not available'); } /** * @param $sql * @param null $array * @return mixed * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function executeAndGetId($sql, $array = null) { $dbDriver = $this->matchRoute($sql); return $dbDriver->executeAndGetId($sql, $array); } /** * @return \ByJG\AnyDataset\Db\DbFunctionsInterface|void * @throws NotImplementedException */ public function getDbHelper() { throw new NotImplementedException('Feature not available'); } /** * @return void * @throws NotImplementedException */ public function getUri() { throw new NotImplementedException('Feature not available'); } /** * @throws NotImplementedException */ public function isSupportMultRowset() { throw new NotImplementedException('Feature not available'); } /** * @param $multipleRowSet * @throws NotImplementedException */ public function setSupportMultRowset($multipleRowSet) { throw new NotImplementedException('Feature not available'); } } __halt_compiler();----SIGNATURE:----PcLUQ15LeTDQ0EIVD2WNNmnZ0TEWAOb0QEXmwwM+khfkKHv7MO0Vhx/QpGXLR3RUrQWW97BJZv3sSNeBrDQrRzrOdnEjzg60vnkQP6LX6t5coc3OOnXCDGL6P7yCTpF09nLXNrgmJaPBcWuzEq/4HfIIg5SI13UOTEHLxyt7DokgXYbRkLPGCaywym+CnTwJz8Jd2svHrP5uFnE/MSf3L3yUtKagaH7PxxlN36MaueRQyQUpzjuXbhPWaWYud4tfMDF94sdjDIqOCVF+e3K3mfxUeGhKWR+aSTR3cgJGF1DDdWJNswWxEPrgBbVirITOnjmyHPytJeKkwBSkICH2lTOjkuXM9jCENjXIpg5JHIq7jQav3jSwB147//1ZAwIPWU+XkquIR7LomtSGmtIt+f8rseg0yUmSkIqPLc7e11x/oJBaE5YiUXvUfze7Gz9t6cG3cnbxHzgpG3208TK6hN8WxvsIFVMUtuBaMyT52tKexcUBE8Ggx9ZDqgCEkH3W6NvslEpleLe6m6QmB6y5PIDyHDHOfKm14SCDPdg1QrkdAVVGzYKshpO6vN5DJlrl4volEJ7G3TBM4iLz7ICvTOL96umJLGX3csI75PXkl6Fz+xcLvS593Ayw4Aruv7rCGvruxXg8e+q+dElxvOrfyNjExghTIfh3KdIDpnX2aMc=----ATTACHMENT:----NzQ1MDY2NDgxODQ3MDM4OCA0Njk1MTI0ODMzMzA0NjE3IDE1NTcxMzMxNjMzOTQxNzk=