*
  • Automatic table prefix handling
  • * */ abstract class DbRepository extends Repository { /** * Return the base table name this repository is responsible for * * This prepends the datasource's table prefix, if available and required. * * @return mixed * * @throws ProgrammingError In case no base table name has been set and * $this->queryColumns does not provide one either */ public function getBaseTable() { return $this->prependTablePrefix(parent::getBaseTable()); } /** * Return the given table with the datasource's prefix being prepended * * @param array|string $table * * @return array|string * * @throws IcingaException In case $table is not of a supported type */ protected function prependTablePrefix($table) { $prefix = $this->ds->getTablePrefix(); if (! $prefix) { return $table; } if (is_array($table)) { foreach ($table as & $tableName) { if (strpos($tableName, $prefix) === false) { $tableName = $prefix . $tableName; } } } elseif (is_string($table)) { $table = (strpos($table, $prefix) === false ? $prefix : '') . $table; } else { throw new IcingaException('Table prefix handling for type "%s" is not supported', type($table)); } return $table; } }