Skip to content

Commit

Permalink
Added index flags support in annotation, xml & yaml mapping drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianolek authored and Ocramius committed Apr 13, 2014
1 parent da24133 commit cc2fb1a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions doctrine-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
</xs:sequence>
<xs:attribute name="name" type="xs:NMTOKEN" use="optional"/>
<xs:attribute name="columns" type="xs:string" use="required"/>
<xs:attribute name="flags" type="xs:string" use="optional"/>
<xs:anyAttribute namespace="##other"/>
</xs:complexType>

Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)

if ($tableAnnot->indexes !== null) {
foreach ($tableAnnot->indexes as $indexAnnot) {
$index = array('columns' => $indexAnnot->columns);
$index = array(
'columns' => $indexAnnot->columns,
'flags' => $indexAnnot->flags
);

if ( ! empty($indexAnnot->name)) {
$primaryTable['indexes'][$indexAnnot->name] = $index;
Expand Down
14 changes: 11 additions & 3 deletions lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,22 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$metadata->table['indexes'] = array();
foreach ($xmlRoot->indexes->index as $index) {
$columns = explode(',', (string)$index['columns']);


if(!isset($index['flags'])) {
$flags = array();
} else {
$flags = explode(',', (string)$index['flags']);
}

if (isset($index['name'])) {
$metadata->table['indexes'][(string)$index['name']] = array(
'columns' => $columns
'columns' => $columns,
'flags' => $flags
);
} else {
$metadata->table['indexes'][] = array(
'columns' => $columns
'columns' => $columns,
'flags' => $flags
);
}
}
Expand Down
13 changes: 12 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,19 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$columns = $index['columns'];
}

if(!isset($index['flags']))
{
$flags = array();
} elseif (is_string($index['flags'])) {
$flags = explode(',', $index['flags']);
$flags = array_map('trim', $flags);
} else {
$flags = $index['flags'];
}

$metadata->table['indexes'][$index['name']] = array(
'columns' => $columns
'columns' => $columns,
'flags' => $flags
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/Mapping/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ final class Index implements Annotation
* @var array<string>
*/
public $columns;

/**
* @var array<string>
*/
public $flags;
}
7 changes: 6 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ public function getSchemaFromMetadata(array $classes)

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']);
}
}

Expand Down

0 comments on commit cc2fb1a

Please sign in to comment.