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: 58: 59: 60: 61: 62: 63: 64: 65:
<?php
namespace Inlm\SchemaGenerator\Dumpers;
use CzProject\SqlGenerator;
use CzProject\SqlSchema;
use Inlm\SchemaGenerator\Bridges;
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()
{
$this->checkIfStarted();
if (!$this->sqlDocument->isEmpty()) {
$dibiDriver = $this->connection->getDriver();
$sqlDriver = $this->prepareDriver($dibiDriver);
foreach ($this->getHeader() as $query) {
$dibiDriver->query($query);
}
$queries = $this->sqlDocument->getSqlQueries($sqlDriver);
foreach ($queries as $query) {
$dibiDriver->query($query);
}
}
$this->stop();
}
protected function prepareDriver($dibiDriver)
{
if (Bridges\Dibi::isMysqlDriver($dibiDriver)) {
return new SqlGenerator\Drivers\MysqlDriver;
}
throw new \Inlm\SchemaGenerator\UnsupportedException('Driver ' . get_class($dibiDriver) . ' is not supported.');
}
}