1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
<?php
namespace Inlm\SchemaGenerator\Dumpers;
use CzProject\SqlGenerator;
use CzProject\SqlSchema;
use Inlm\SchemaGenerator\Diffs;
use Inlm\SchemaGenerator\IDumper;
class DibiDumper extends AbstractSqlDumper
{
private $connection;
public function __construct($connection)
{
if (!($connection instanceof \Dibi\Connection || $connection instanceof \DibiConnection)) {
throw new \Inlm\SchemaGenerator\InvalidArgumentException('Connection must be instance of Dibi\Connection or DibiConnection.');
}
$this->connection = $connection;
}
public function end()
{
if (!$this->sqlDocument->isEmpty()) {
$dibiDriver = $this->connection->getDriver();
$sqlDriver = NULL;
if ($dibiDriver instanceof \Dibi\Drivers\MySqlDriver || $dibiDriver instanceof DibiMySqlDriver) {
$sqlDriver = new SqlGenerator\Drivers\MysqlDriver;
} elseif ($dibiDriver instanceof \Dibi\Drivers\MySqliDriver || $dibiDriver instanceof DibiMySqliDriver) {
$sqlDriver = new SqlGenerator\Drivers\MysqlDriver;
} else {
throw new \Inlm\SchemaGenerator\UnsupportedException('Driver ' . get_class($dibiDriver) . ' is not supported.');
}
$queries = $this->sqlDocument->getSqlQueries($sqlDriver);
foreach ($queries as $query) {
$dibiDriver->query($query);
}
}
$this->sqlDocument = NULL;
}
}