Merge pull request #980 from adrianolek/convert-mapping-options
Added options attribute export to Annotation, Xml & Yaml exporters.
This commit is contained in:
commit
da24133306
@ -123,7 +123,7 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
||||
}
|
||||
}
|
||||
|
||||
if ($tableAnnot->options !== null) {
|
||||
if ($tableAnnot->options) {
|
||||
$primaryTable['options'] = $tableAnnot->options;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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');
|
||||
|
@ -6,7 +6,12 @@
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<entity name="Doctrine\Tests\ORM\Tools\Export\User" table="cms_users">
|
||||
|
||||
<options>
|
||||
<option name="engine">MyISAM</option>
|
||||
<option name="foo">
|
||||
<option name="bar">baz</option>
|
||||
</option>
|
||||
</options>
|
||||
<lifecycle-callbacks>
|
||||
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
|
||||
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersistToo"/>
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user