Added options attribute export to Annotation, Xml & Yaml
exporters.
This commit is contained in:
parent
8d4821b4dc
commit
553883bdd1
@ -48,5 +48,5 @@ final class Table implements Annotation
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $options = array();
|
public $options;
|
||||||
}
|
}
|
||||||
|
@ -910,6 +910,10 @@ public function __construct()
|
|||||||
$table[] = 'name="' . $metadata->table['name'] . '"';
|
$table[] = 'name="' . $metadata->table['name'] . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($metadata->table['options']) && $metadata->table['options']) {
|
||||||
|
$table[] = 'options={' . $this->_exportOptions((array) $metadata->table['options']) . '}';
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($metadata->table['uniqueConstraints']) && $metadata->table['uniqueConstraints']) {
|
if (isset($metadata->table['uniqueConstraints']) && $metadata->table['uniqueConstraints']) {
|
||||||
$constraints = $this->generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']);
|
$constraints = $this->generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']);
|
||||||
$table[] = 'uniqueConstraints={' . $constraints . '}';
|
$table[] = 'uniqueConstraints={' . $constraints . '}';
|
||||||
@ -1556,4 +1560,25 @@ public function __construct()
|
|||||||
|
|
||||||
return static::$generatorStrategyMap[$type];
|
return static::$generatorStrategyMap[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports (nested) option elements.
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
private function _exportOptions(array $options)
|
||||||
|
{
|
||||||
|
$optionsStr = array();
|
||||||
|
|
||||||
|
foreach($options as $name => $option)
|
||||||
|
{
|
||||||
|
if (is_array($option)) {
|
||||||
|
$optionsStr[] = '"' . $name . '"={' . $this->_exportOptions($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\" ".
|
"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\" />");
|
"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) {
|
if ($metadata->isMappedSuperclass) {
|
||||||
$root = $xml->addChild('mapped-superclass');
|
$root = $xml->addChild('mapped-superclass');
|
||||||
} else {
|
} else {
|
||||||
@ -73,6 +69,12 @@ class XmlExporter extends AbstractExporter
|
|||||||
$root->addAttribute('inheritance-type', $this->_getInheritanceTypeString($metadata->inheritanceType));
|
$root->addAttribute('inheritance-type', $this->_getInheritanceTypeString($metadata->inheritanceType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($metadata->table['options'])) {
|
||||||
|
$optionsXml = $root->addChild('options');
|
||||||
|
|
||||||
|
$this->_exportOptions($optionsXml, $metadata->table['options']);
|
||||||
|
}
|
||||||
|
|
||||||
if ($metadata->discriminatorColumn) {
|
if ($metadata->discriminatorColumn) {
|
||||||
$discriminatorColumnXml = $root->addChild('discriminator-column');
|
$discriminatorColumnXml = $root->addChild('discriminator-column');
|
||||||
$discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']);
|
$discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']);
|
||||||
@ -106,6 +108,9 @@ class XmlExporter extends AbstractExporter
|
|||||||
$indexXml = $indexesXml->addChild('index');
|
$indexXml = $indexesXml->addChild('index');
|
||||||
$indexXml->addAttribute('name', $name);
|
$indexXml->addAttribute('name', $name);
|
||||||
$indexXml->addAttribute('columns', implode(',', $index['columns']));
|
$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);
|
return $this->_asXml($xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports (nested) option elements.
|
||||||
|
*
|
||||||
|
* @param \SimpleXMLElement $parentXml
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
private function _exportOptions(\SimpleXMLElement $parentXml, array $options)
|
||||||
|
{
|
||||||
|
foreach ($options as $name => $option) {
|
||||||
|
$optionXml = $parentXml->addChild('option');
|
||||||
|
$optionXml->addAttribute('name', (string) $name);
|
||||||
|
|
||||||
|
if (is_array($option)) {
|
||||||
|
$this->_exportOptions($optionXml, $option);
|
||||||
|
} else {
|
||||||
|
$optionXml[0] = (string) $option;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \SimpleXMLElement $simpleXml
|
* @param \SimpleXMLElement $simpleXml
|
||||||
*
|
*
|
||||||
|
@ -85,6 +85,10 @@ class YamlExporter extends AbstractExporter
|
|||||||
$array['uniqueConstraints'] = $metadata->table['uniqueConstraints'];
|
$array['uniqueConstraints'] = $metadata->table['uniqueConstraints'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($metadata->table['options'])) {
|
||||||
|
$array['options'] = $metadata->table['options'];
|
||||||
|
}
|
||||||
|
|
||||||
$fieldMappings = $metadata->fieldMappings;
|
$fieldMappings = $metadata->fieldMappings;
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
@ -157,6 +157,8 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
|||||||
public function testTableIsExported($class)
|
public function testTableIsExported($class)
|
||||||
{
|
{
|
||||||
$this->assertEquals('cms_users', $class->table['name']);
|
$this->assertEquals('cms_users', $class->table['name']);
|
||||||
|
$this->assertEquals(array('engine' => 'MyISAM', 'foo' => array('bar' => 'baz')),
|
||||||
|
$class->table['options']);
|
||||||
|
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Tools\Export;
|
|||||||
/**
|
/**
|
||||||
* @Entity
|
* @Entity
|
||||||
* @HasLifecycleCallbacks
|
* @HasLifecycleCallbacks
|
||||||
* @Table(name="cms_users")
|
* @Table(name="cms_users",options={"engine"="MyISAM","foo"={"bar"="baz"}})
|
||||||
*/
|
*/
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
|||||||
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
||||||
$metadata->setPrimaryTable(array(
|
$metadata->setPrimaryTable(array(
|
||||||
'name' => 'cms_users',
|
'name' => 'cms_users',
|
||||||
|
'options' => array('engine' => 'MyISAM', 'foo' => array('bar' => 'baz')),
|
||||||
));
|
));
|
||||||
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
|
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
|
||||||
$metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
|
$metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
|
||||||
|
@ -6,7 +6,12 @@
|
|||||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||||
|
|
||||||
<entity name="Doctrine\Tests\ORM\Tools\Export\User" table="cms_users">
|
<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-callbacks>
|
||||||
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
|
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
|
||||||
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersistToo"/>
|
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersistToo"/>
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
Doctrine\Tests\ORM\Tools\Export\User:
|
Doctrine\Tests\ORM\Tools\Export\User:
|
||||||
type: entity
|
type: entity
|
||||||
table: cms_users
|
table: cms_users
|
||||||
|
options:
|
||||||
|
engine: MyISAM
|
||||||
|
foo: { bar: baz }
|
||||||
id:
|
id:
|
||||||
id:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user