RepositoryQuery: Validate the table passed when calling from()
refs #8826
This commit is contained in:
parent
10b158a182
commit
4833ff109c
|
@ -74,21 +74,6 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
|
|||
parent::__construct($ds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -277,6 +262,25 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the requested table exists
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string The table's name, with the table prefix being prepended
|
||||
*
|
||||
* @throws ProgrammingError In case the given table does not exist
|
||||
*/
|
||||
public function requireTable($table)
|
||||
{
|
||||
$statementColumns = $this->getStatementColumns();
|
||||
if (! isset($statementColumns[$table])) {
|
||||
$table = parent::requireTable($table);
|
||||
}
|
||||
|
||||
return $this->prependTablePrefix($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this repository's query columns of the given table mapped to their respective aliases
|
||||
*
|
||||
|
|
|
@ -589,6 +589,25 @@ abstract class Repository implements Selectable
|
|||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the requested table exists
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string The table's name, may differ from the given one
|
||||
*
|
||||
* @throws ProgrammingError In case the given table does not exist
|
||||
*/
|
||||
public function requireTable($table)
|
||||
{
|
||||
$queryColumns = $this->getQueryColumns();
|
||||
if (! isset($queryColumns[$table])) {
|
||||
throw new ProgrammingError('Table "%s" not found', $table);
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse the given filter, require each column for the given table and convert all values
|
||||
*
|
||||
|
|
|
@ -76,6 +76,7 @@ class RepositoryQuery implements QueryInterface, Iterator
|
|||
*/
|
||||
public function from($target, array $columns = null)
|
||||
{
|
||||
$target = $this->repository->requireTable($target);
|
||||
$this->query = $this->repository
|
||||
->getDataSource()
|
||||
->select()
|
||||
|
|
Loading…
Reference in New Issue