Commit ec4bd256 authored by beberlei's avatar beberlei

[2.0] DDC-412 - Fixed YAML Driver not allowing multiple lifecycle callbacks...

[2.0] DDC-412 - Fixed YAML Driver not allowing multiple lifecycle callbacks per event. Backwards-incompatible change
parent c7ac5650
<?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;
}
}
...@@ -380,11 +380,13 @@ class YamlDriver extends AbstractFileDriver ...@@ -380,11 +380,13 @@ 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) {
foreach ($methods as $method) {
$metadata->addLifecycleCallback($method, constant('\Doctrine\ORM\Events::' . $type)); $metadata->addLifecycleCallback($method, constant('\Doctrine\ORM\Events::' . $type));
} }
} }
} }
}
/** /**
* Constructs a joinColumn mapping array based on the information * Constructs a joinColumn mapping array based on the information
......
...@@ -154,7 +154,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase ...@@ -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 ...@@ -220,6 +231,7 @@ class User
*/ */
public $groups; public $groups;
/** /**
* @PrePersist * @PrePersist
*/ */
...@@ -227,6 +239,12 @@ class User ...@@ -227,6 +239,12 @@ class User
{ {
} }
/**
* @PrePersist
*/
public function doOtherStuffOnPrePersistToo() {
}
/** /**
* @PostPersist * @PostPersist
*/ */
......
...@@ -9,6 +9,7 @@ ...@@ -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>
......
...@@ -47,5 +47,5 @@ Doctrine\Tests\ORM\Mapping\User: ...@@ -47,5 +47,5 @@ Doctrine\Tests\ORM\Mapping\User:
cascade: cascade:
- all - all
lifecycleCallbacks: lifecycleCallbacks:
doStuffOnPrePersist: prePersist prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
doStuffOnPostPersist: postPersist postPersist: [ doStuffOnPostPersist ]
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment