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: 66: 67: 68:
<?php
namespace Inlm\SchemaGenerator\Utils;
use CzProject\SqlSchema;
class GeneratorIndex
{
private $tableName;
private $definition;
public function __construct($tableName, SqlSchema\Index $definition)
{
$this->tableName = $tableName;
$this->definition = $definition;
}
public function getDefinition()
{
return $this->definition;
}
public function checkCompatibility($type, $columns)
{
$indexName = $this->definition->getName();
if (!is_array($columns)) {
$columns = array($columns);
}
$origType = $this->definition->getType();
if ($origType !== $type) {
throw new \Inlm\SchemaGenerator\IncompatibleException("Type mismatch for index '$indexName' in table '{$this->tableName}'. Original type '$origType', new type '$type'.");
}
$origColumns = array();
foreach ($this->definition->getColumns() as $column) {
$origColumns[] = $column->getName();
}
if ($origColumns !== $columns) {
throw new \Inlm\SchemaGenerator\IncompatibleException("Mismatched columns for index '$indexName' in table '{$this->tableName}'. Original columns (" . implode(', ', $origColumns) . "), new columns (" . implode(', ', $columns) . ").");
}
}
}