Skip to content

Instantly share code, notes, and snippets.

@jsor
Created December 13, 2011 15:14
Show Gist options
  • Save jsor/1472474 to your computer and use it in GitHub Desktop.
Save jsor/1472474 to your computer and use it in GitHub Desktop.
diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php
index 46e7fe5..135aef7 100644
--- a/lib/Doctrine/DBAL/Schema/Column.php
+++ b/lib/Doctrine/DBAL/Schema/Column.php
@@ -94,6 +94,11 @@ class Column extends AbstractAsset
protected $_comment = null;
/**
+ * @var array
+ */
+ protected $_customSchemaOptions = array();
+
+ /**
* Create a new Column
*
* @param string $columnName
@@ -341,6 +346,53 @@ class Column extends AbstractAsset
}
/**
+ * @param string $name
+ * @param mixed $value
+ * @return Column
+ */
+ public function setCustomSchemaOption($name, $value)
+ {
+ $this->_customSchemaOptions[$name] = $value;
+ return $this;
+ }
+
+ /**
+ * @param string $name
+ * @return boolean
+ */
+ public function hasCustomSchemaOption($name)
+ {
+ return isset($this->_customSchemaOptions[$name]);
+ }
+
+ /**
+ * @param string $name
+ * @return mixed
+ */
+ public function getCustomSchemaOption($name)
+ {
+ return $this->_customSchemaOptions[$name];
+ }
+
+ /**
+ * @param array $customSchemaOptions
+ * @return Column
+ */
+ public function setCustomSchemaOptions(array $customSchemaOptions)
+ {
+ $this->_customSchemaOptions = $customSchemaOptions;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getCustomSchemaOptions()
+ {
+ return $this->_customSchemaOptions;
+ }
+
+ /**
* @param Visitor $visitor
*/
public function visit(\Doctrine\DBAL\Schema\Visitor $visitor)
@@ -366,6 +418,6 @@ class Column extends AbstractAsset
'autoincrement' => $this->_autoincrement,
'columnDefinition' => $this->_columnDefinition,
'comment' => $this->_comment,
- ), $this->_platformOptions);
+ ), $this->_platformOptions, $this->_customSchemaOptions);
}
}
\ No newline at end of file
diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php
index 0544c6e..fdb71fd 100644
--- a/lib/Doctrine/DBAL/Schema/Comparator.php
+++ b/lib/Doctrine/DBAL/Schema/Comparator.php
@@ -355,6 +355,22 @@ class Comparator
$changedProperties[] = 'comment';
}
+ $options1 = $column1->getCustomSchemaOptions();
+ $options2 = $column2->getCustomSchemaOptions();
+
+ $commonKeys = array_keys(array_intersect_key($options1, $options2));
+
+ foreach ($commonKeys as $key) {
+ if ($options1[$key] !== $options2[$key]) {
+ $changedProperties[] = $key;
+ break;
+ }
+ }
+
+ $diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
+
+ $changedProperties = array_merge($changedProperties, $diffKeys);
+
return $changedProperties;
}
diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
index 2220103..2051061 100644
--- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
+++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
@@ -30,6 +30,11 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($column->hasPlatformOption('foo'));
$this->assertEquals('bar', $column->getPlatformOption('foo'));
$this->assertFalse($column->hasPlatformOption('bar'));
+
+ $this->assertEquals(array('bar' => 'baz'), $column->getCustomSchemaOptions());
+ $this->assertTrue($column->hasCustomSchemaOption('bar'));
+ $this->assertEquals('baz', $column->getCustomSchemaOption('bar'));
+ $this->assertFalse($column->hasCustomSchemaOption('foo'));
}
public function testToArray()
@@ -48,6 +53,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'columnDefinition' => null,
'comment' => null,
'foo' => 'bar',
+ 'bar' => 'baz'
);
$this->assertEquals($expected, $this->createColumn()->toArray());
@@ -67,6 +73,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'fixed' => true,
'default' => 'baz',
'platformOptions' => array('foo' => 'bar'),
+ 'customSchemaOptions' => array('bar' => 'baz'),
);
$string = Type::getType('string');
diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
index 0eb8347..7daafe6 100644
--- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
+++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
@@ -193,6 +193,22 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $c->diffColumn($column1, $column1));
}
+ public function testCompareChangedColumns_ChangeCustomSchemaOption()
+ {
+ $column1 = new Column('charfield1', Type::getType('string'));
+ $column2 = new Column('charfield1', Type::getType('string'));
+
+ $column1->setCustomSchemaOption('foo', 'bar');
+ $column2->setCustomSchemaOption('foo', 'bar');
+
+ $column1->setCustomSchemaOption('foo1', 'bar1');
+ $column2->setCustomSchemaOption('foo2', 'bar2');
+
+ $c = new Comparator();
+ $this->assertEquals(array('foo1', 'foo2'), $c->diffColumn($column1, $column2));
+ $this->assertEquals(array(), $c->diffColumn($column1, $column1));
+ }
+
public function testCompareRemovedIndex()
{
$schema1 = new Schema( array(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment