for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* components
*
* @author Wolfy-J
*/
namespace Spiral\Migrations\Atomizer;
use Spiral\Atomizer\Exceptions\AtomizerException;
use Spiral\Database\DatabaseManager;
use Spiral\Database\Schemas\Prototypes\AbstractTable;
* Provides ability to identify database and local table name based on given AbstractTable schema.
* Utilizes DatabaseManager.
class AliasLookup
{
* @var DatabaseManager
private $dbal;
* @param DatabaseManager $dbal
public function __construct(DatabaseManager $dbal)
$this->dbal = $dbal;
}
* Local database alias (no prefix included).
* @param AbstractTable $table
* @param bool $initial Request initial table name.
* @return string
public function tableAlias(AbstractTable $table, bool $initial = false): string
if ($initial) {
return substr($table->getInitialName(), strlen($table->getPrefix()));
return substr($table->getName(), strlen($table->getPrefix()));
* Database associated with given table schema.
public function databaseAlias(AbstractTable $table): string
foreach ($this->dbal->getDatabases() as $database) {
if (
$table->getDriver() == $database->getDriver()
&& $table->getPrefix() == $database->getPrefix()
) {
return $database->getName();
throw new AtomizerException("Unable to find database associated with {$table}");