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:----Ks6zUSiQtbgc/1G3Kd78tuJvf5aI57w3rwPj67ZSO2t+C7Hqh/oBnhlbBIyMlWVNRvnIA4UpQZm867/+pwsLC9hnn5NaPJEtEwPmWw+PGD2a2UGb15TLtU7FDS1m5xA2yTIE+aO2w1Y5rx9W5MXbcU2HYokzzqYVd3/taRBrILBUONUBWpPYKs3nIMb0YKMfGhWVl4ES/0FyrQGQOH9C4SN9YaiUXkZ7VhXNN8pIyAli8PnTkKfpHAS/q1fxS0zCZ8V9tWueLBWqKWSairbTHqnxKb01O0fV+QZQvbAyIzCS7xrSKUZ2SsyepxnkfIipb4WjxKj+FXHgTnDMmiG0Q2Fmwl/SJkZ10shQ3PvtdLGW4HifTAzZ28x5eNtD3YE7Gc4qjIKabphKLzBM84WA9A0CEZ0nB4P7q5kXSmWmyccubDfyLqPKRKd4C03NWxznCeAZt1f+ujuNSMnbITGLI1SXQdxtQnUke84hozVoVmwjxjhbqHbTVJwNEPKRxEiTsEfMpnIDq/Fd4AkSOdtDIkUi9WvvXYRrdL748Mb9pLlcaJDRd1tHFayB6mIo924/4skI2L8BIWJZ4TtD8OrhQknbNqIsCfsrG5odcUpjHP0PpH6m4GFgZ73tN627qEptEwnwcc2chWuSNfB3cHMCwIfI9sWVribNaO+P8+UQTNw=----ATTACHMENT:----NzE1MjczNDcyMTU1NDg0NSA5NzAyOTM4OTY5NzA1MTIzIDk5Njk4NDk0MzA5NjI4NjY=