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:----SoA3DpI0SoMWzZ2Gbv9zhuw8UP/olnnJiqb/iFWTjPFXdIrfbf6CTKVld1qt63Gve02FSvXFZN8xtIJkRkMvnbAWNasQ3WI54evIAlh8VoYXRZXOKZxWoAbHMJi6PC1he0NbO3oSU+H0hSETQtSFLq6jLSwlivQ2pQUVqpzZY5l7bejt0TRS/swUyIKhl68v6jY5N+NhMafGm9ZNU0yMi+zcuq0xgYBtfQis07RFdXf3KYH8Tlk2Fjnn++4daU9uOrAKLcIOewr5ICXI8pFvrECdJWfXFRlwl3RRZRn29EFDV7V740qMeHjYimyBj/1OFfRj6/hD/mt2+5vH2dDU/1exybjfF8SQMw7pk69vvcqqz8ZpOBBx4f9JGqodmrGxXSaFxIFsX/t1GNW/Hj3ZRfu8YbvEQqXpJikUTt5YZnR6Cn9HcnbICzuWLjY0VpbHIcTOvev79ViKQMfYRQ41aSqQw/4CHIZlphsOG1W/oaVr9qLQ+8WEQnaSq4wrFNsva0x1Cy2ZkfyZdhuf4fIszzLE1rxXBQ4KvUWLEPubmThklrDV6VCd0QKVaRZVrpcyRyKf8NFIxrLhT1J1d4Ma2Clr1CRBW+mNCmOLtMuVnQ8bcTk8DWWGF+8jfLeLswvhiRj6N/Xrc7ss/NNsREiRzXYWLbFa0VafgbqGPCFMKfI=----ATTACHMENT:----OTQ1OTczMTIwMjYyMTkwMyAzMzA5NDIxMDgyOTM4NTc3IDgxMzE4OTk4MTAwMzUxNDU=