diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 1a1cab811..e127d8372 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -123,7 +123,7 @@ class AnnotationDriver extends AbstractAnnotationDriver } } - if ($tableAnnot->options !== null) { + if ($tableAnnot->options) { $primaryTable['options'] = $tableAnnot->options; } diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 79d9ae0a1..d7f225145 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -912,6 +912,10 @@ public function __construct() $table[] = 'name="' . $metadata->table['name'] . '"'; } + if (isset($metadata->table['options']) && $metadata->table['options']) { + $table[] = 'options={' . $this->exportTableOptions((array) $metadata->table['options']) . '}'; + } + if (isset($metadata->table['uniqueConstraints']) && $metadata->table['uniqueConstraints']) { $constraints = $this->generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']); $table[] = 'uniqueConstraints={' . $constraints . '}'; @@ -1558,4 +1562,24 @@ public function __construct() return static::$generatorStrategyMap[$type]; } + + /** + * Exports (nested) option elements. + * + * @param array $options + */ + private function exportTableOptions(array $options) + { + $optionsStr = array(); + + foreach($options as $name => $option) { + if (is_array($option)) { + $optionsStr[] = '"' . $name . '"={' . $this->exportTableOptions($option) . '}'; + } else { + $optionsStr[] = '"' . $name . '"="' . (string) $option . '"'; + } + } + + return implode(',', $optionsStr); + } } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index f69eaec59..094889c1a 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -45,10 +45,6 @@ class XmlExporter extends AbstractExporter "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ". "xsi:schemaLocation=\"http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd\" />"); - /*$xml->addAttribute('xmlns', 'http://doctrine-project.org/schemas/orm/doctrine-mapping'); - $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); - $xml->addAttribute('xsi:schemaLocation', 'http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd');*/ - if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); } else { @@ -73,6 +69,12 @@ class XmlExporter extends AbstractExporter $root->addAttribute('inheritance-type', $this->_getInheritanceTypeString($metadata->inheritanceType)); } + if (isset($metadata->table['options'])) { + $optionsXml = $root->addChild('options'); + + $this->exportTableOptions($optionsXml, $metadata->table['options']); + } + if ($metadata->discriminatorColumn) { $discriminatorColumnXml = $root->addChild('discriminator-column'); $discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']); @@ -106,6 +108,9 @@ class XmlExporter extends AbstractExporter $indexXml = $indexesXml->addChild('index'); $indexXml->addAttribute('name', $name); $indexXml->addAttribute('columns', implode(',', $index['columns'])); + if(isset($index['flags'])) { + $indexXml->addAttribute('flags', implode(',', $index['flags'])); + } } } @@ -380,6 +385,26 @@ class XmlExporter extends AbstractExporter return $this->_asXml($xml); } + /** + * Exports (nested) option elements. + * + * @param \SimpleXMLElement $parentXml + * @param array $options + */ + private function exportTableOptions(\SimpleXMLElement $parentXml, array $options) + { + foreach ($options as $name => $option) { + $optionXml = $parentXml->addChild('option'); + $optionXml->addAttribute('name', (string) $name); + + if (is_array($option)) { + $this->exportTableOptions($optionXml, $option); + } else { + $optionXml[0] = (string) $option; + } + } + } + /** * @param \SimpleXMLElement $simpleXml * diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index addab7f71..4b401c9f0 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -85,6 +85,10 @@ class YamlExporter extends AbstractExporter $array['uniqueConstraints'] = $metadata->table['uniqueConstraints']; } + if (isset($metadata->table['options'])) { + $array['options'] = $metadata->table['options']; + } + $fieldMappings = $metadata->fieldMappings; $ids = array(); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 3376b7443..c792746cc 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -155,6 +155,8 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testTableIsExported($class) { $this->assertEquals('cms_users', $class->table['name']); + $this->assertEquals(array('engine' => 'MyISAM', 'foo' => array('bar' => 'baz')), + $class->table['options']); return $class; } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php index 5a82cc6f1..f153a7c83 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Tools\Export; /** * @Entity * @HasLifecycleCallbacks - * @Table(name="cms_users") + * @Table(name="cms_users",options={"engine"="MyISAM","foo"={"bar"="baz"}}) */ class User { diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php index 2a52bc3d8..f272ca0aa 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php @@ -5,6 +5,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable(array( 'name' => 'cms_users', + 'options' => array('engine' => 'MyISAM', 'foo' => array('bar' => 'baz')), )); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist'); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml index 22d2852b0..dfec31ec0 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml @@ -6,7 +6,12 @@ http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + + + + + diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml index 25071d9b3..b43aefad7 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml @@ -1,6 +1,9 @@ Doctrine\Tests\ORM\Tools\Export\User: type: entity table: cms_users + options: + engine: MyISAM + foo: { bar: baz } id: id: type: integer