diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index b6728f0de..f7364b7f7 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -341,6 +341,7 @@ + diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index e127d8372..3f46e2c95 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -102,6 +102,10 @@ class AnnotationDriver extends AbstractAnnotationDriver if ($tableAnnot->indexes !== null) { foreach ($tableAnnot->indexes as $indexAnnot) { $index = array('columns' => $indexAnnot->columns); + + if ( ! empty($indexAnnot->flags)) { + $index['flags'] = $indexAnnot->flags; + } if ( ! empty($indexAnnot->name)) { $primaryTable['indexes'][$indexAnnot->name] = $index; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 3d867e1c5..e08ee7ae6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -194,17 +194,17 @@ class XmlDriver extends FileDriver // Evaluate if (isset($xmlRoot->indexes)) { $metadata->table['indexes'] = array(); - foreach ($xmlRoot->indexes->index as $index) { - $columns = explode(',', (string)$index['columns']); - - if (isset($index['name'])) { - $metadata->table['indexes'][(string)$index['name']] = array( - 'columns' => $columns - ); + foreach ($xmlRoot->indexes->index as $indexXml) { + $index = array('columns' => explode(',', (string) $indexXml['columns'])); + + if (isset($indexXml['flags'])) { + $index['flags'] = explode(',', (string) $indexXml['flags']); + } + + if (isset($indexXml['name'])) { + $metadata->table['indexes'][(string) $indexXml['name']] = $index; } else { - $metadata->table['indexes'][] = array( - 'columns' => $columns - ); + $metadata->table['indexes'][] = $index; } } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 48aa7021b..2772913cc 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -201,21 +201,26 @@ class YamlDriver extends FileDriver // Evaluate indexes if (isset($element['indexes'])) { - foreach ($element['indexes'] as $name => $index) { - if ( ! isset($index['name'])) { - $index['name'] = $name; + foreach ($element['indexes'] as $name => $indexYml) { + if ( ! isset($indexYml['name'])) { + $indexYml['name'] = $name; } - if (is_string($index['columns'])) { - $columns = explode(',', $index['columns']); - $columns = array_map('trim', $columns); + if (is_string($indexYml['columns'])) { + $index = array('columns' => array_map('trim', explode(',', $indexYml['columns']))); } else { - $columns = $index['columns']; + $index = array('columns' => $indexYml['columns']); } - $metadata->table['indexes'][$index['name']] = array( - 'columns' => $columns - ); + if (isset($indexYml['flags'])) { + if (is_string($indexYml['flags'])) { + $index['flags'] = array_map('trim', explode(',', $indexYml['flags'])); + } else { + $index['flags'] = $indexYml['flags']; + } + } + + $metadata->table['indexes'][$indexYml['name']] = $index; } } diff --git a/lib/Doctrine/ORM/Mapping/Index.php b/lib/Doctrine/ORM/Mapping/Index.php index a6696c4b6..ff4532d47 100644 --- a/lib/Doctrine/ORM/Mapping/Index.php +++ b/lib/Doctrine/ORM/Mapping/Index.php @@ -34,4 +34,9 @@ final class Index implements Annotation * @var array */ public $columns; + + /** + * @var array + */ + public $flags; } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index ad8b84f68..9bca3ed66 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -264,7 +264,11 @@ class SchemaTool if (isset($class->table['indexes'])) { foreach ($class->table['indexes'] as $indexName => $indexData) { - $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName); + if( ! isset($indexData['flags'])) { + $indexData['flags'] = array(); + } + + $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array)$indexData['flags']); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 49e387e5d..7a22dc1da 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -73,6 +73,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase return $class; } + public function testEntityIndexFlags() + { + $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment'); + + $this->assertEquals(array( + 0 => array( + 'columns' => array('content'), + 'flags' => array('fulltext') + ) + ), $class->table['indexes']); + } + /** * @depends testEntityTableNameAndInheritance * @param ClassMetadata $class @@ -1266,3 +1278,36 @@ class DDC807SubClasse2 {} class Address {} class Phonenumber {} class Group {} + +/** + * @Entity + * @Table(indexes={@Index(columns={"content"}, flags={"fulltext"})}) + */ +class Comment +{ + /** + * @Column(type="text") + */ + private $content; + + public static function loadMetadata(ClassMetadataInfo $metadata) + { + $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); + $metadata->setPrimaryTable(array( + 'indexes' => array( + array('columns' => array('content'), 'flags' => array('fulltext')) + ) + )); + + $metadata->mapField(array( + 'fieldName' => 'content', + 'type' => 'text', + 'scale' => 0, + 'length' => NULL, + 'unique' => false, + 'nullable' => false, + 'precision' => 0, + 'columnName' => 'content', + )); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php new file mode 100644 index 000000000..124aafe1d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php @@ -0,0 +1,21 @@ +setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); +$metadata->setPrimaryTable(array( + 'indexes' => array( + array('columns' => array('content'), 'flags' => array('fulltext')) + ) + )); + +$metadata->mapField(array( + 'fieldName' => 'content', + 'type' => 'text', + 'scale' => 0, + 'length' => NULL, + 'unique' => false, + 'nullable' => false, + 'precision' => 0, + 'columnName' => 'content', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml new file mode 100644 index 000000000..659ddccd8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml new file mode 100644 index 000000000..2186f6a27 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml @@ -0,0 +1,9 @@ +Doctrine\Tests\ORM\Mapping\Comment: + type: entity + fields: + content: + type: text + indexes: + 0: + columns: content + flags: fulltext