1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

[2.0] DDC-412 - Fixed YAML Driver not allowing multiple lifecycle callbacks per event. Backwards-incompatible change

This commit is contained in:
beberlei 2010-03-15 19:29:07 +00:00
parent c7ac5650c2
commit ec4bd256d5
5 changed files with 72 additions and 85 deletions

View file

@ -1,34 +0,0 @@
<?php
namespace Doctrine\ORM\Event;
use Doctrine\Common\EventArgs;
/**
* Class that holds event arguments for a preInsert/preUpdate event.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class PreInsertUpdateEventArgs extends EventArgs
{
private $_entity;
private $_entityChangeSet;
public function __construct($entity, array $changeSet)
{
$this->_entity = $entity;
$this->_entityChangeSet = $changeSet;
}
public function getEntity()
{
return $this->_entity;
}
public function getEntityChangeSet()
{
return $this->_entityChangeSet;
}
}

View file

@ -56,7 +56,7 @@ class YamlDriver extends AbstractFileDriver
public function loadMetadataForClass($className, ClassMetadataInfo $metadata) public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{ {
$element = $this->getElement($className); $element = $this->getElement($className);
if ($element['type'] == 'entity') { if ($element['type'] == 'entity') {
$metadata->setCustomRepositoryClass( $metadata->setCustomRepositoryClass(
isset($element['repositoryClass']) ? $element['repositoryClass'] : null isset($element['repositoryClass']) ? $element['repositoryClass'] : null
@ -71,11 +71,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(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType']))); $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
} }
@ -107,13 +107,13 @@ class YamlDriver extends AbstractFileDriver
if ( ! isset($index['name'])) { if ( ! isset($index['name'])) {
$index['name'] = $name; $index['name'] = $name;
} }
if (is_string($index['columns'])) { if (is_string($index['columns'])) {
$columns = explode(',', $index['columns']); $columns = explode(',', $index['columns']);
} else { } else {
$columns = $index['columns']; $columns = $index['columns'];
} }
$metadata->primaryTable['indexes'][$index['name']] = array( $metadata->primaryTable['indexes'][$index['name']] = array(
'columns' => $columns 'columns' => $columns
); );
@ -126,13 +126,13 @@ class YamlDriver extends AbstractFileDriver
if ( ! isset($unique['name'])) { if ( ! isset($unique['name'])) {
$unique['name'] = $name; $unique['name'] = $name;
} }
if (is_string($unique['columns'])) { if (is_string($unique['columns'])) {
$columns = explode(',', $unique['columns']); $columns = explode(',', $unique['columns']);
} else { } else {
$columns = $unique['columns']; $columns = $unique['columns'];
} }
$metadata->primaryTable['uniqueConstraints'][$unique['name']] = array( $metadata->primaryTable['uniqueConstraints'][$unique['name']] = array(
'columns' => $columns 'columns' => $columns
); );
@ -147,11 +147,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'])) {
@ -217,7 +217,7 @@ class YamlDriver extends AbstractFileDriver
if (isset($fieldMapping['columnDefinition'])) { if (isset($fieldMapping['columnDefinition'])) {
$mapping['columnDefinition'] = $fieldMapping['columnDefinition']; $mapping['columnDefinition'] = $fieldMapping['columnDefinition'];
} }
$metadata->mapField($mapping); $metadata->mapField($mapping);
} }
} }
@ -229,16 +229,16 @@ class YamlDriver extends AbstractFileDriver
'fieldName' => $name, 'fieldName' => $name,
'targetEntity' => $oneToOneElement['targetEntity'] 'targetEntity' => $oneToOneElement['targetEntity']
); );
if (isset($oneToOneElement['fetch'])) { if (isset($oneToOneElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToOneElement['fetch']); $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToOneElement['fetch']);
} }
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'])) {
@ -246,11 +246,11 @@ 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);
} }
} }
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
} }
@ -270,11 +270,11 @@ class YamlDriver extends AbstractFileDriver
'targetEntity' => $oneToManyElement['targetEntity'], 'targetEntity' => $oneToManyElement['targetEntity'],
'mappedBy' => $oneToManyElement['mappedBy'] 'mappedBy' => $oneToManyElement['mappedBy']
); );
if (isset($oneToManyElement['fetch'])) { if (isset($oneToManyElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToManyElement['fetch']); $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToManyElement['fetch']);
} }
if (isset($oneToManyElement['cascade'])) { if (isset($oneToManyElement['cascade'])) {
$mapping['cascade'] = $oneToManyElement['cascade']; $mapping['cascade'] = $oneToManyElement['cascade'];
} }
@ -282,7 +282,7 @@ class YamlDriver extends AbstractFileDriver
if (isset($oneToManyElement['orderBy'])) { if (isset($oneToManyElement['orderBy'])) {
$mapping['orderBy'] = $oneToManyElement['orderBy']; $mapping['orderBy'] = $oneToManyElement['orderBy'];
} }
$metadata->mapOneToMany($mapping); $metadata->mapOneToMany($mapping);
} }
} }
@ -291,16 +291,16 @@ class YamlDriver extends AbstractFileDriver
if (isset($element['manyToOne'])) { if (isset($element['manyToOne'])) {
foreach ($element['manyToOne'] as $name => $manyToOneElement) { foreach ($element['manyToOne'] as $name => $manyToOneElement) {
$mapping = array( $mapping = array(
'fieldName' => $name, 'fieldName' => $name,
'targetEntity' => $manyToOneElement['targetEntity'] 'targetEntity' => $manyToOneElement['targetEntity']
); );
if (isset($manyToOneElement['fetch'])) { if (isset($manyToOneElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToOneElement['fetch']); $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToOneElement['fetch']);
} }
$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'])) {
@ -308,17 +308,17 @@ 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);
} }
} }
$mapping['joinColumns'] = $joinColumns; $mapping['joinColumns'] = $joinColumns;
if (isset($manyToOneElement['cascade'])) { if (isset($manyToOneElement['cascade'])) {
$mapping['cascade'] = $manyToOneElement['cascade']; $mapping['cascade'] = $manyToOneElement['cascade'];
} }
$metadata->mapManyToOne($mapping); $metadata->mapManyToOne($mapping);
} }
} }
@ -330,11 +330,11 @@ class YamlDriver extends AbstractFileDriver
'fieldName' => $name, 'fieldName' => $name,
'targetEntity' => $manyToManyElement['targetEntity'] 'targetEntity' => $manyToManyElement['targetEntity']
); );
if (isset($manyToManyElement['fetch'])) { if (isset($manyToManyElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToManyElement['fetch']); $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToManyElement['fetch']);
} }
if (isset($manyToManyElement['mappedBy'])) { if (isset($manyToManyElement['mappedBy'])) {
$mapping['mappedBy'] = $manyToManyElement['mappedBy']; $mapping['mappedBy'] = $manyToManyElement['mappedBy'];
} else if (isset($manyToManyElement['joinTable'])) { } else if (isset($manyToManyElement['joinTable'])) {
@ -342,30 +342,30 @@ 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;
} }
if (isset($manyToManyElement['cascade'])) { if (isset($manyToManyElement['cascade'])) {
$mapping['cascade'] = $manyToManyElement['cascade']; $mapping['cascade'] = $manyToManyElement['cascade'];
} }
@ -380,8 +380,10 @@ class YamlDriver extends AbstractFileDriver
// Evaluate lifeCycleCallbacks // Evaluate lifeCycleCallbacks
if (isset($element['lifecycleCallbacks'])) { if (isset($element['lifecycleCallbacks'])) {
foreach ($element['lifecycleCallbacks'] as $method => $type) { foreach ($element['lifecycleCallbacks'] as $type => $methods) {
$metadata->addLifecycleCallback($method, constant('\Doctrine\ORM\Events::' . $type)); foreach ($methods as $method) {
$metadata->addLifecycleCallback($method, constant('\Doctrine\ORM\Events::' . $type));
}
} }
} }
} }
@ -389,7 +391,7 @@ class YamlDriver extends AbstractFileDriver
/** /**
* Constructs a joinColumn mapping array based on the information * Constructs a joinColumn mapping array based on the information
* found in the given join column element. * found in the given join column element.
* *
* @param $joinColumnElement The array join column element * @param $joinColumnElement The array join column element
* @return array The mapping array. * @return array The mapping array.
*/ */
@ -399,23 +401,23 @@ class YamlDriver extends AbstractFileDriver
'name' => $joinColumnElement['name'], 'name' => $joinColumnElement['name'],
'referencedColumnName' => $joinColumnElement['referencedColumnName'] 'referencedColumnName' => $joinColumnElement['referencedColumnName']
); );
if (isset($joinColumnElement['fieldName'])) { if (isset($joinColumnElement['fieldName'])) {
$joinColumn['fieldName'] = (string) $joinColumnElement['fieldName']; $joinColumn['fieldName'] = (string) $joinColumnElement['fieldName'];
} }
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'];
} }
@ -423,10 +425,10 @@ class YamlDriver extends AbstractFileDriver
if (isset($joinColumnElement['columnDefinition'])) { if (isset($joinColumnElement['columnDefinition'])) {
$joinColumn['columnDefinition'] = $joinColumnElement['columnDefinition']; $joinColumn['columnDefinition'] = $joinColumnElement['columnDefinition'];
} }
return $joinColumn; return $joinColumn;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -154,7 +154,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
} }
/** /**
* @depends testLifecycleCallbacks * @depends testManyToManyAssociationWithCascadeAll
* @param ClassMetadata $class
*/
public function testLifecycleCallbacksSupportMultipleMethodNames($class) {
$this->assertEquals(count($class->lifecycleCallbacks['prePersist']), 2);
$this->assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
return $class;
}
/**
* @depends testLifecycleCallbacksSupportMultipleMethodNames
* @param ClassMetadata $class * @param ClassMetadata $class
*/ */
public function testJoinColumnUniqueAndNullable($class) public function testJoinColumnUniqueAndNullable($class)
@ -220,6 +231,7 @@ class User
*/ */
public $groups; public $groups;
/** /**
* @PrePersist * @PrePersist
*/ */
@ -227,6 +239,12 @@ class User
{ {
} }
/**
* @PrePersist
*/
public function doOtherStuffOnPrePersistToo() {
}
/** /**
* @PostPersist * @PostPersist
*/ */

View file

@ -9,6 +9,7 @@
<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="postPersist" method="doStuffOnPostPersist"/> <lifecycle-callback type="postPersist" method="doStuffOnPostPersist"/>
</lifecycle-callbacks> </lifecycle-callbacks>

View file

@ -47,5 +47,5 @@ Doctrine\Tests\ORM\Mapping\User:
cascade: cascade:
- all - all
lifecycleCallbacks: lifecycleCallbacks:
doStuffOnPrePersist: prePersist prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
doStuffOnPostPersist: postPersist postPersist: [ doStuffOnPostPersist ]