Repository: Add native support for virtual table names
This commit is contained in:
parent
d32c3d2a52
commit
df7a2ee0a9
|
@ -52,6 +52,16 @@ abstract class Repository implements Selectable
|
||||||
*/
|
*/
|
||||||
protected $baseTable;
|
protected $baseTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The virtual tables being provided
|
||||||
|
*
|
||||||
|
* This may be initialized by concrete repository implementations with an array
|
||||||
|
* where a key is the name of a virtual table and its value the real table name.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $virtualTables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The query columns being provided
|
* The query columns being provided
|
||||||
*
|
*
|
||||||
|
@ -255,6 +265,32 @@ abstract class Repository implements Selectable
|
||||||
return $this->baseTable;
|
return $this->baseTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the virtual tables being provided
|
||||||
|
*
|
||||||
|
* Calls $this->initializeVirtualTables() in case $this->virtualTables is null.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getVirtualTables()
|
||||||
|
{
|
||||||
|
if ($this->virtualTables === null) {
|
||||||
|
$this->virtualTables = $this->initializeVirtualTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->virtualTables;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrite this in your repository implementation in case you need to initialize the virtual tables lazily
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function initializeVirtualTables()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the query columns being provided
|
* Return the query columns being provided
|
||||||
*
|
*
|
||||||
|
@ -792,7 +828,7 @@ abstract class Repository implements Selectable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that the requested table exists
|
* Validate that the requested table exists and resolve it's real name if necessary
|
||||||
*
|
*
|
||||||
* @param string $table The table to validate
|
* @param string $table The table to validate
|
||||||
* @param RepositoryQuery $query An optional query to pass as context
|
* @param RepositoryQuery $query An optional query to pass as context
|
||||||
|
@ -809,6 +845,11 @@ abstract class Repository implements Selectable
|
||||||
throw new ProgrammingError('Table "%s" not found', $table);
|
throw new ProgrammingError('Table "%s" not found', $table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$virtualTables = $this->getVirtualTables();
|
||||||
|
if (isset($virtualTables[$table])) {
|
||||||
|
$table = $virtualTables[$table];
|
||||||
|
}
|
||||||
|
|
||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue