1
0
mirror of synced 2025-01-31 04:21:44 +03:00

[2.0] Fixing spacing and adding precision and scale in Annotations driver. Also introduced options item in Annotation and Yaml mapping drivers. Missing XML driver implementation.

This commit is contained in:
guilhermeblanco 2009-09-04 18:35:40 +00:00
parent 203b46dea2
commit eb25422617
4 changed files with 117 additions and 5 deletions

View File

@ -77,16 +77,19 @@ class AnnotationDriver implements Driver
'name' => $tableAnnot->name, 'name' => $tableAnnot->name,
'schema' => $tableAnnot->schema 'schema' => $tableAnnot->schema
); );
if ($tableAnnot->indexes !== null) { if ($tableAnnot->indexes !== null) {
foreach ($tableAnnot->indexes as $indexAnnot) { foreach ($tableAnnot->indexes as $indexAnnot) {
$primaryTable['indexes'][$indexAnnot->name] = array('fields' => $indexAnnot->columns); $primaryTable['indexes'][$indexAnnot->name] = array('fields' => $indexAnnot->columns);
} }
} }
if ($tableAnnot->uniqueConstraints !== null) { if ($tableAnnot->uniqueConstraints !== null) {
foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) { foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
$primaryTable['uniqueConstraints'][] = $uniqueConstraint->columns; $primaryTable['uniqueConstraints'][] = $uniqueConstraint->columns;
} }
} }
$metadata->setPrimaryTable($primaryTable); $metadata->setPrimaryTable($primaryTable);
} }
@ -129,6 +132,7 @@ class AnnotationDriver implements Driver
// Check for JoinColummn/JoinColumns annotations // Check for JoinColummn/JoinColumns annotations
$joinColumns = array(); $joinColumns = array();
if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) { if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) {
$joinColumns[] = array( $joinColumns[] = array(
'name' => $joinColumnAnnot->name, 'name' => $joinColumnAnnot->name,
@ -157,24 +161,34 @@ class AnnotationDriver implements Driver
if ($columnAnnot->type == null) { if ($columnAnnot->type == null) {
throw DoctrineException::propertyTypeIsRequired($property->getName()); throw DoctrineException::propertyTypeIsRequired($property->getName());
} }
$mapping['type'] = $columnAnnot->type; $mapping['type'] = $columnAnnot->type;
$mapping['length'] = $columnAnnot->length; $mapping['length'] = $columnAnnot->length;
$mapping['precision'] = $columnAnnot->precision;
$mapping['scale'] = $columnAnnot->scale;
$mapping['nullable'] = $columnAnnot->nullable; $mapping['nullable'] = $columnAnnot->nullable;
$mapping['options'] = $columnAnnot->options;
if (isset($columnAnnot->default)) { if (isset($columnAnnot->default)) {
$mapping['default'] = $columnAnnot->default; $mapping['default'] = $columnAnnot->default;
} }
if (isset($columnAnnot->name)) { if (isset($columnAnnot->name)) {
$mapping['columnName'] = $columnAnnot->name; $mapping['columnName'] = $columnAnnot->name;
} }
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
$mapping['id'] = true; $mapping['id'] = true;
} }
if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) { if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) {
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy)); $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
} }
if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) { if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) {
$metadata->setVersionMapping($mapping); $metadata->setVersionMapping($mapping);
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
// Check for SequenceGenerator/TableGenerator definition // Check for SequenceGenerator/TableGenerator definition
@ -207,6 +221,7 @@ class AnnotationDriver implements Driver
$metadata->mapManyToOne($mapping); $metadata->mapManyToOne($mapping);
} else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { } else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) {
$joinTable = array(); $joinTable = array();
if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) { if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) {
$joinTable = array( $joinTable = array(
'name' => $joinTableAnnot->name, 'name' => $joinTableAnnot->name,
@ -249,24 +264,31 @@ class AnnotationDriver implements Driver
foreach ($class->getMethods() as $method) { foreach ($class->getMethods() as $method) {
if ($method->isPublic()) { if ($method->isPublic()) {
$annotations = $this->_reader->getMethodAnnotations($method); $annotations = $this->_reader->getMethodAnnotations($method);
if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) { if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
} }
if (isset($annotations['Doctrine\ORM\Mapping\PostPersist'])) { if (isset($annotations['Doctrine\ORM\Mapping\PostPersist'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist);
} }
if (isset($annotations['Doctrine\ORM\Mapping\PreUpdate'])) { if (isset($annotations['Doctrine\ORM\Mapping\PreUpdate'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate);
} }
if (isset($annotations['Doctrine\ORM\Mapping\PostUpdate'])) { if (isset($annotations['Doctrine\ORM\Mapping\PostUpdate'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate);
} }
if (isset($annotations['Doctrine\ORM\Mapping\PreRemove'])) { if (isset($annotations['Doctrine\ORM\Mapping\PreRemove'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove);
} }
if (isset($annotations['Doctrine\ORM\Mapping\PostRemove'])) { if (isset($annotations['Doctrine\ORM\Mapping\PostRemove'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove);
} }
if (isset($annotations['Doctrine\ORM\Mapping\PostLoad'])) { if (isset($annotations['Doctrine\ORM\Mapping\PostLoad'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad); $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad);
} }
@ -286,6 +308,7 @@ class AnnotationDriver implements Driver
public function isTransient($className) public function isTransient($className)
{ {
$classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className)); $classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));
return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) && return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']); ! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
} }

View File

@ -56,10 +56,13 @@ final class JoinColumns extends Annotation {}
final class Column extends Annotation { final class Column extends Annotation {
public $type; public $type;
public $length; public $length;
public $precision = 0; // The precision for a decimal (exact numeric) column (Applies only for decimal column)
public $scale = 0; // The scale for a decimal (exact numeric) column (Applies only for decimal column)
public $unique = false; public $unique = false;
public $nullable = false; public $nullable = false;
public $default; public $default;
public $name; public $name;
public $options = array();
} }
final class OneToOne extends Annotation { final class OneToOne extends Annotation {
public $targetEntity; public $targetEntity;

View File

@ -59,9 +59,11 @@ class XmlDriver extends AbstractFileDriver
if (isset($xmlRoot['table'])) { if (isset($xmlRoot['table'])) {
$metadata->primaryTable['name'] = (string)$xmlRoot['table']; $metadata->primaryTable['name'] = (string)$xmlRoot['table'];
} }
if (isset($xmlRoot['schema'])) { if (isset($xmlRoot['schema'])) {
$metadata->primaryTable['schema'] = (string)$xmlRoot['schema']; $metadata->primaryTable['schema'] = (string)$xmlRoot['schema'];
} }
if (isset($xmlRoot['inheritance-type'])) { if (isset($xmlRoot['inheritance-type'])) {
$metadata->setInheritanceType((string)$xmlRoot['inheritance-type']); $metadata->setInheritanceType((string)$xmlRoot['inheritance-type']);
} }
@ -89,8 +91,9 @@ class XmlDriver extends AbstractFileDriver
// Evaluate <indexes...> // Evaluate <indexes...>
if (isset($xmlRoot->indexes)) { if (isset($xmlRoot->indexes)) {
foreach ($xmlRoot->indexes->index as $index) { foreach ($xmlRoot->indexes->index as $index) {
$metadata->primaryTable['indexes'][$index['name']] = array('fields' => $metadata->primaryTable['indexes'][$index['name']] = array(
explode(',', $index['columns'])); 'fields' => explode(',', $index['columns'])
);
} }
} }
@ -108,21 +111,27 @@ class XmlDriver extends AbstractFileDriver
'fieldName' => (string)$fieldMapping['name'], 'fieldName' => (string)$fieldMapping['name'],
'type' => (string)$fieldMapping['type'] 'type' => (string)$fieldMapping['type']
); );
if (isset($fieldMapping['column'])) { if (isset($fieldMapping['column'])) {
$mapping['columnName'] = (string)$fieldMapping['column']; $mapping['columnName'] = (string)$fieldMapping['column'];
} }
if (isset($fieldMapping['length'])) { if (isset($fieldMapping['length'])) {
$mapping['length'] = (int)$fieldMapping['length']; $mapping['length'] = (int)$fieldMapping['length'];
} }
if (isset($fieldMapping['precision'])) { if (isset($fieldMapping['precision'])) {
$mapping['precision'] = (int)$fieldMapping['precision']; $mapping['precision'] = (int)$fieldMapping['precision'];
} }
if (isset($fieldMapping['scale'])) { if (isset($fieldMapping['scale'])) {
$mapping['scale'] = (int)$fieldMapping['scale']; $mapping['scale'] = (int)$fieldMapping['scale'];
} }
if (isset($fieldMapping['version']) && $fieldMapping['version']) { if (isset($fieldMapping['version']) && $fieldMapping['version']) {
$metadata->setVersionMapping($mapping); $metadata->setVersionMapping($mapping);
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
} }
} }
@ -134,9 +143,11 @@ class XmlDriver extends AbstractFileDriver
'fieldName' => (string)$idElement['name'], 'fieldName' => (string)$idElement['name'],
'type' => (string)$idElement['type'] 'type' => (string)$idElement['type']
); );
if (isset($idElement['column'])) { if (isset($idElement['column'])) {
$mapping['columnName'] = (string)$idElement['column']; $mapping['columnName'] = (string)$idElement['column'];
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
if (isset($idElement->generator)) { if (isset($idElement->generator)) {
@ -164,10 +175,12 @@ class XmlDriver extends AbstractFileDriver
'fieldName' => (string)$oneToOneElement['field'], 'fieldName' => (string)$oneToOneElement['field'],
'targetEntity' => (string)$oneToOneElement['target-entity'], 'targetEntity' => (string)$oneToOneElement['target-entity'],
); );
if (isset($oneToOneElement['mapped-by'])) { if (isset($oneToOneElement['mapped-by'])) {
$mapping['mappedBy'] = (string)$oneToOneElement['mapped-by']; $mapping['mappedBy'] = (string)$oneToOneElement['mapped-by'];
} else { } else {
$joinColumns = array(); $joinColumns = array();
if (isset($oneToOneElement->{'join-column'})) { if (isset($oneToOneElement->{'join-column'})) {
$joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'}); $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'});
} else if (isset($oneToOneElement->{'join-columns'})) { } else if (isset($oneToOneElement->{'join-columns'})) {
@ -177,14 +190,18 @@ class XmlDriver extends AbstractFileDriver
} else { } else {
throw MappingException::invalidMapping($mapping['fieldName']); throw MappingException::invalidMapping($mapping['fieldName']);
} }
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
} }
if (isset($oneToOneElement->cascade)) { if (isset($oneToOneElement->cascade)) {
$mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade); $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
} }
if (isset($oneToOneElement->{'orphan-removal'})) { if (isset($oneToOneElement->{'orphan-removal'})) {
$mapping['orphanRemoval'] = (bool)$oneToOneElement->{'orphan-removal'}; $mapping['orphanRemoval'] = (bool)$oneToOneElement->{'orphan-removal'};
} }
$metadata->mapOneToOne($mapping); $metadata->mapOneToOne($mapping);
} }
} }
@ -197,12 +214,15 @@ class XmlDriver extends AbstractFileDriver
'targetEntity' => (string)$oneToManyElement['target-entity'], 'targetEntity' => (string)$oneToManyElement['target-entity'],
'mappedBy' => (string)$oneToManyElement['mapped-by'] 'mappedBy' => (string)$oneToManyElement['mapped-by']
); );
if (isset($oneToManyElement->cascade)) { if (isset($oneToManyElement->cascade)) {
$mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade); $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
} }
if (isset($oneToManyElement->{'orphan-removal'})) { if (isset($oneToManyElement->{'orphan-removal'})) {
$mapping['orphanRemoval'] = (bool)$oneToManyElement->{'orphan-removal'}; $mapping['orphanRemoval'] = (bool)$oneToManyElement->{'orphan-removal'};
} }
$metadata->mapOneToMany($mapping); $metadata->mapOneToMany($mapping);
} }
} }
@ -214,7 +234,9 @@ class XmlDriver extends AbstractFileDriver
'fieldName' => (string)$manyToOneElement['field'], 'fieldName' => (string)$manyToOneElement['field'],
'targetEntity' => (string)$manyToOneElement['target-entity'] 'targetEntity' => (string)$manyToOneElement['target-entity']
); );
$joinColumns = array(); $joinColumns = array();
if (isset($manyToOneElement->{'join-column'})) { if (isset($manyToOneElement->{'join-column'})) {
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'}); $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'});
} else if (isset($manyToOneElement->{'join-columns'})) { } else if (isset($manyToOneElement->{'join-columns'})) {
@ -222,18 +244,23 @@ class XmlDriver extends AbstractFileDriver
if (!isset($joinColumnElement['name'])) { if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $name; $joinColumnElement['name'] = $name;
} }
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
} }
} else { } else {
throw MappingException::invalidMapping($mapping['fieldName']); throw MappingException::invalidMapping($mapping['fieldName']);
} }
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
if (isset($manyToOneElement->cascade)) { if (isset($manyToOneElement->cascade)) {
$mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade); $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade);
} }
if (isset($manyToOneElement->{'orphan-removal'})) { if (isset($manyToOneElement->{'orphan-removal'})) {
$mapping['orphanRemoval'] = (bool)$manyToOneElement->{'orphan-removal'}; $mapping['orphanRemoval'] = (bool)$manyToOneElement->{'orphan-removal'};
} }
$metadata->mapManyToOne($mapping); $metadata->mapManyToOne($mapping);
} }
} }
@ -245,6 +272,7 @@ class XmlDriver extends AbstractFileDriver
'fieldName' => (string)$manyToManyElement['field'], 'fieldName' => (string)$manyToManyElement['field'],
'targetEntity' => (string)$manyToManyElement['target-entity'] 'targetEntity' => (string)$manyToManyElement['target-entity']
); );
if (isset($manyToManyElement['mappedBy'])) { if (isset($manyToManyElement['mappedBy'])) {
$mapping['mappedBy'] = (string)$manyToManyElement['mapped-by']; $mapping['mappedBy'] = (string)$manyToManyElement['mapped-by'];
} else if (isset($manyToManyElement->{'join-table'})) { } else if (isset($manyToManyElement->{'join-table'})) {
@ -252,25 +280,32 @@ class XmlDriver extends AbstractFileDriver
$joinTable = array( $joinTable = array(
'name' => (string)$joinTableElement['name'] 'name' => (string)$joinTableElement['name']
); );
if (isset($joinTableElement['schema'])) { if (isset($joinTableElement['schema'])) {
$joinTable['schema'] = (string)$joinTableElement['schema']; $joinTable['schema'] = (string)$joinTableElement['schema'];
} }
foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
$joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); $joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
} }
foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
$joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); $joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
} }
$mapping['joinTable'] = $joinTable; $mapping['joinTable'] = $joinTable;
} else { } else {
throw MappingException::invalidMapping($mapping['fieldName']); throw MappingException::invalidMapping($mapping['fieldName']);
} }
if (isset($manyToManyElement->cascade)) { if (isset($manyToManyElement->cascade)) {
$mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade); $mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade);
} }
if (isset($manyToManyElement->{'orphan-removal'})) { if (isset($manyToManyElement->{'orphan-removal'})) {
$mapping['orphanRemoval'] = (bool)$manyToManyElement->{'orphan-removal'}; $mapping['orphanRemoval'] = (bool)$manyToManyElement->{'orphan-removal'};
} }
$metadata->mapManyToMany($mapping); $metadata->mapManyToMany($mapping);
} }
} }
@ -279,6 +314,7 @@ class XmlDriver extends AbstractFileDriver
if (isset($xmlRoot->{'lifecycle-callbacks'})) { if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$method = $class->getMethod((string)$lifecycleCallback['method']); $method = $class->getMethod((string)$lifecycleCallback['method']);
if ($method->isPublic()) { if ($method->isPublic()) {
$metadata->addLifecycleCallback($method->getName(), constant('\Doctrine\ORM\Events::' . (string)$lifecycleCallback['type'])); $metadata->addLifecycleCallback($method->getName(), constant('\Doctrine\ORM\Events::' . (string)$lifecycleCallback['type']));
} }
@ -326,15 +362,19 @@ class XmlDriver extends AbstractFileDriver
'name' => (string)$joinColumnElement['name'], 'name' => (string)$joinColumnElement['name'],
'referencedColumnName' => (string)$joinColumnElement['referenced-column-name'] 'referencedColumnName' => (string)$joinColumnElement['referenced-column-name']
); );
if (isset($joinColumnElement['unique'])) { if (isset($joinColumnElement['unique'])) {
$joinColumn['unique'] = (bool)$joinColumnElement['unique']; $joinColumn['unique'] = (bool)$joinColumnElement['unique'];
} }
if (isset($joinColumnElement['nullable'])) { if (isset($joinColumnElement['nullable'])) {
$joinColumn['nullable'] = (bool)$joinColumnElement['nullable']; $joinColumn['nullable'] = (bool)$joinColumnElement['nullable'];
} }
if (isset($joinColumnElement['onDelete'])) { if (isset($joinColumnElement['onDelete'])) {
$joinColumn['onDelete'] = (string)$joinColumnElement['on-delete']; $joinColumn['onDelete'] = (string)$joinColumnElement['on-delete'];
} }
if (isset($joinColumnElement['onUpdate'])) { if (isset($joinColumnElement['onUpdate'])) {
$joinColumn['onUpdate'] = (string)$joinColumnElement['on-update']; $joinColumn['onUpdate'] = (string)$joinColumnElement['on-update'];
} }
@ -351,15 +391,19 @@ class XmlDriver extends AbstractFileDriver
private function _getCascadeMappings($cascadeElement) private function _getCascadeMappings($cascadeElement)
{ {
$cascades = array(); $cascades = array();
if (isset($cascadeElement->{'cascade-persist'})) { if (isset($cascadeElement->{'cascade-persist'})) {
$cascades[] = 'persist'; $cascades[] = 'persist';
} }
if (isset($cascadeElement->{'cascade-remove'})) { if (isset($cascadeElement->{'cascade-remove'})) {
$cascades[] = 'remove'; $cascades[] = 'remove';
} }
if (isset($cascadeElement->{'cascade-merge'})) { if (isset($cascadeElement->{'cascade-merge'})) {
$cascades[] = 'merge'; $cascades[] = 'merge';
} }
if (isset($cascadeElement->{'cascade-refresh'})) { if (isset($cascadeElement->{'cascade-refresh'})) {
$cascades[] = 'refresh'; $cascades[] = 'refresh';
} }

View File

@ -60,9 +60,11 @@ class YamlDriver extends AbstractFileDriver
if (isset($element['table'])) { if (isset($element['table'])) {
$metadata->primaryTable['name'] = $element['table']; $metadata->primaryTable['name'] = $element['table'];
} }
if (isset($element['schema'])) { if (isset($element['schema'])) {
$metadata->primaryTable['schema'] = $element['schema']; $metadata->primaryTable['schema'] = $element['schema'];
} }
if (isset($element['inheritanceType'])) { if (isset($element['inheritanceType'])) {
$metadata->setInheritanceType($element['inheritanceType']); $metadata->setInheritanceType($element['inheritanceType']);
} }
@ -90,8 +92,9 @@ class YamlDriver extends AbstractFileDriver
// Evaluate indexes // Evaluate indexes
if (isset($element['indexes'])) { if (isset($element['indexes'])) {
foreach ($element['indexes'] as $index) { foreach ($element['indexes'] as $index) {
$metadata->primaryTable['indexes'][$index['name']] = array('fields' => $metadata->primaryTable['indexes'][$index['name']] = array(
explode(',', $index['columns'])); 'fields' => explode(',', $index['columns'])
);
} }
} }
@ -109,21 +112,31 @@ class YamlDriver extends AbstractFileDriver
'fieldName' => $name, 'fieldName' => $name,
'type' => $fieldMapping['type'] 'type' => $fieldMapping['type']
); );
if (isset($fieldMapping['column'])) { if (isset($fieldMapping['column'])) {
$mapping['columnName'] = $fieldMapping['column']; $mapping['columnName'] = $fieldMapping['column'];
} }
if (isset($fieldMapping['length'])) { if (isset($fieldMapping['length'])) {
$mapping['length'] = $fieldMapping['length']; $mapping['length'] = $fieldMapping['length'];
} }
if (isset($fieldMapping['precision'])) { if (isset($fieldMapping['precision'])) {
$mapping['precision'] = $fieldMapping['precision']; $mapping['precision'] = $fieldMapping['precision'];
} }
if (isset($fieldMapping['scale'])) { if (isset($fieldMapping['scale'])) {
$mapping['scale'] = $fieldMapping['scale']; $mapping['scale'] = $fieldMapping['scale'];
} }
if (isset($fieldMapping['options'])) {
$mapping['options'] = $fieldMapping['options'];
}
if (isset($fieldMapping['version']) && $fieldMapping['version']) { if (isset($fieldMapping['version']) && $fieldMapping['version']) {
$metadata->setVersionMapping($mapping); $metadata->setVersionMapping($mapping);
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
} }
} }
@ -135,9 +148,11 @@ class YamlDriver extends AbstractFileDriver
'fieldName' => $name, 'fieldName' => $name,
'type' => $idElement['type'] 'type' => $idElement['type']
); );
if (isset($idElement['column'])) { if (isset($idElement['column'])) {
$mapping['columnName'] = $idElement['column']; $mapping['columnName'] = $idElement['column'];
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
if (isset($idElement['generator'])) { if (isset($idElement['generator'])) {
@ -153,10 +168,12 @@ class YamlDriver extends AbstractFileDriver
'fieldName' => $name, 'fieldName' => $name,
'targetEntity' => $oneToOneElement['targetEntity'] 'targetEntity' => $oneToOneElement['targetEntity']
); );
if (isset($oneToOneElement['mappedBy'])) { if (isset($oneToOneElement['mappedBy'])) {
$mapping['mappedBy'] = $oneToOneElement['mappedBy']; $mapping['mappedBy'] = $oneToOneElement['mappedBy'];
} else { } else {
$joinColumns = array(); $joinColumns = array();
if (isset($oneToOneElement['joinColumn'])) { if (isset($oneToOneElement['joinColumn'])) {
$joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement['joinColumn']); $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement['joinColumn']);
} else if (isset($oneToOneElement['joinColumns'])) { } else if (isset($oneToOneElement['joinColumns'])) {
@ -164,11 +181,13 @@ class YamlDriver extends AbstractFileDriver
if (!isset($joinColumnElement['name'])) { if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $name; $joinColumnElement['name'] = $name;
} }
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
} }
} else { } else {
throw MappingException::invalidMapping($mapping['fieldName']); throw MappingException::invalidMapping($mapping['fieldName']);
} }
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
} }
@ -188,9 +207,11 @@ class YamlDriver extends AbstractFileDriver
'targetEntity' => $oneToManyElement['targetEntity'], 'targetEntity' => $oneToManyElement['targetEntity'],
'mappedBy' => $oneToManyElement['mappedBy'] 'mappedBy' => $oneToManyElement['mappedBy']
); );
if (isset($oneToManyElement['cascade'])) { if (isset($oneToManyElement['cascade'])) {
$mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement['cascade']); $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement['cascade']);
} }
$metadata->mapOneToMany($mapping); $metadata->mapOneToMany($mapping);
} }
} }
@ -202,7 +223,9 @@ class YamlDriver extends AbstractFileDriver
'fieldName' => $name, 'fieldName' => $name,
'targetEntity' => $manyToOneElement['targetEntity'] 'targetEntity' => $manyToOneElement['targetEntity']
); );
$joinColumns = array(); $joinColumns = array();
if (isset($manyToOneElement['joinColumn'])) { if (isset($manyToOneElement['joinColumn'])) {
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement['joinColumn']); $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement['joinColumn']);
} else if (isset($manyToOneElement['joinColumns'])) { } else if (isset($manyToOneElement['joinColumns'])) {
@ -210,15 +233,19 @@ class YamlDriver extends AbstractFileDriver
if (!isset($joinColumnElement['name'])) { if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $name; $joinColumnElement['name'] = $name;
} }
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
} }
} else { } else {
throw MappingException::invalidMapping($mapping['fieldName']); throw MappingException::invalidMapping($mapping['fieldName']);
} }
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
if (isset($manyToOneElement['cascade'])) { if (isset($manyToOneElement['cascade'])) {
$mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement['cascade']); $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement['cascade']);
} }
$metadata->mapManyToOne($mapping); $metadata->mapManyToOne($mapping);
} }
} }
@ -238,21 +265,27 @@ class YamlDriver extends AbstractFileDriver
$joinTable = array( $joinTable = array(
'name' => $joinTableElement['name'] 'name' => $joinTableElement['name']
); );
if (isset($joinTableElement['schema'])) { if (isset($joinTableElement['schema'])) {
$joinTable['schema'] = $joinTableElement['schema']; $joinTable['schema'] = $joinTableElement['schema'];
} }
foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) { foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) {
if (!isset($joinColumnElement['name'])) { if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $name; $joinColumnElement['name'] = $name;
} }
$joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); $joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
} }
foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) { foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) {
if (!isset($joinColumnElement['name'])) { if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $name; $joinColumnElement['name'] = $name;
} }
$joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); $joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
} }
$mapping['joinTable'] = $joinTable; $mapping['joinTable'] = $joinTable;
} else { } else {
throw MappingException::invalidMapping($mapping['fieldName']); throw MappingException::invalidMapping($mapping['fieldName']);
@ -270,6 +303,7 @@ class YamlDriver extends AbstractFileDriver
if (isset($element['lifecycleCallbacks'])) { if (isset($element['lifecycleCallbacks'])) {
foreach ($element['lifecycleCallbacks'] as $method => $type) { foreach ($element['lifecycleCallbacks'] as $method => $type) {
$method = $class->getMethod($method); $method = $class->getMethod($method);
if ($method->isPublic()) { if ($method->isPublic()) {
$metadata->addLifecycleCallback($method->getName(), constant('\Doctrine\ORM\Events::' . $type)); $metadata->addLifecycleCallback($method->getName(), constant('\Doctrine\ORM\Events::' . $type));
} }
@ -290,15 +324,19 @@ class YamlDriver extends AbstractFileDriver
'name' => $joinColumnElement['name'], 'name' => $joinColumnElement['name'],
'referencedColumnName' => $joinColumnElement['referencedColumnName'] 'referencedColumnName' => $joinColumnElement['referencedColumnName']
); );
if (isset($joinColumnElement['unique'])) { if (isset($joinColumnElement['unique'])) {
$joinColumn['unique'] = (bool) $joinColumnElement['unique']; $joinColumn['unique'] = (bool) $joinColumnElement['unique'];
} }
if (isset($joinColumnElement['nullable'])) { if (isset($joinColumnElement['nullable'])) {
$joinColumn['nullable'] = (bool) $joinColumnElement['nullable']; $joinColumn['nullable'] = (bool) $joinColumnElement['nullable'];
} }
if (isset($joinColumnElement['onDelete'])) { if (isset($joinColumnElement['onDelete'])) {
$joinColumn['onDelete'] = $joinColumnElement['onDelete']; $joinColumn['onDelete'] = $joinColumnElement['onDelete'];
} }
if (isset($joinColumnElement['onUpdate'])) { if (isset($joinColumnElement['onUpdate'])) {
$joinColumn['onUpdate'] = $joinColumnElement['onUpdate']; $joinColumn['onUpdate'] = $joinColumnElement['onUpdate'];
} }
@ -315,15 +353,19 @@ class YamlDriver extends AbstractFileDriver
private function _getCascadeMappings($cascadeElement) private function _getCascadeMappings($cascadeElement)
{ {
$cascades = array(); $cascades = array();
if (isset($cascadeElement['cascadePersist'])) { if (isset($cascadeElement['cascadePersist'])) {
$cascades[] = 'persist'; $cascades[] = 'persist';
} }
if (isset($cascadeElement['cascadeRemove'])) { if (isset($cascadeElement['cascadeRemove'])) {
$cascades[] = 'remove'; $cascades[] = 'remove';
} }
if (isset($cascadeElement['cascadeMerge'])) { if (isset($cascadeElement['cascadeMerge'])) {
$cascades[] = 'merge'; $cascades[] = 'merge';
} }
if (isset($cascadeElement['cascadeRefresh'])) { if (isset($cascadeElement['cascadeRefresh'])) {
$cascades[] = 'refresh'; $cascades[] = 'refresh';
} }