remove @LifecycleCallback
This commit is contained in:
parent
ffc8d032c7
commit
c60e3e4ba4
14 changed files with 13 additions and 199 deletions
|
@ -51,6 +51,7 @@
|
||||||
<xs:enumeration value="preRemove"/>
|
<xs:enumeration value="preRemove"/>
|
||||||
<xs:enumeration value="postRemove"/>
|
<xs:enumeration value="postRemove"/>
|
||||||
<xs:enumeration value="postLoad"/>
|
<xs:enumeration value="postLoad"/>
|
||||||
|
<xs:enumeration value="preFlush"/>
|
||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
|
|
||||||
|
|
|
@ -435,14 +435,6 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate as lifecycle callback if the listener class is not given.
|
|
||||||
if(empty($entityListenersAnnot->value)) {
|
|
||||||
/* @var $method \Doctrine\ORM\Mapping\LifecycleCallback */
|
|
||||||
foreach ($entityListenersAnnot->callbacks as $callback) {
|
|
||||||
$metadata->addLifecycleCallback($callback->method, $callback->event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate @HasLifecycleCallbacks annotation
|
// Evaluate @HasLifecycleCallbacks annotation
|
||||||
|
|
|
@ -64,5 +64,4 @@ require_once __DIR__.'/../AssociationOverride.php';
|
||||||
require_once __DIR__.'/../AssociationOverrides.php';
|
require_once __DIR__.'/../AssociationOverrides.php';
|
||||||
require_once __DIR__.'/../AttributeOverride.php';
|
require_once __DIR__.'/../AttributeOverride.php';
|
||||||
require_once __DIR__.'/../AttributeOverrides.php';
|
require_once __DIR__.'/../AttributeOverrides.php';
|
||||||
require_once __DIR__.'/../EntityListeners.php';
|
require_once __DIR__.'/../EntityListeners.php';
|
||||||
require_once __DIR__.'/../LifecycleCallback.php';
|
|
|
@ -19,10 +19,10 @@
|
||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use SimpleXMLElement,
|
use SimpleXMLElement;
|
||||||
Doctrine\Common\Persistence\Mapping\Driver\FileDriver,
|
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
|
||||||
Doctrine\Common\Persistence\Mapping\ClassMetadata,
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
use Doctrine\ORM\Mapping\MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XmlDriver is a metadata driver that enables mapping through XML files.
|
* XmlDriver is a metadata driver that enables mapping through XML files.
|
||||||
|
@ -560,28 +560,12 @@ class XmlDriver extends FileDriver
|
||||||
// Evaluate entity listener
|
// Evaluate entity listener
|
||||||
if (isset($xmlRoot->{'entity-listeners'})) {
|
if (isset($xmlRoot->{'entity-listeners'})) {
|
||||||
foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) {
|
foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) {
|
||||||
$listeners = array();
|
|
||||||
|
|
||||||
foreach ($listenerElement as $callbackElement) {
|
foreach ($listenerElement as $callbackElement) {
|
||||||
$eventName = (string) $callbackElement['type'];
|
$eventName = (string) $callbackElement['type'];
|
||||||
$methodName = (string) $callbackElement['method'];
|
$methodName = (string) $callbackElement['method'];
|
||||||
|
$className = (string) $listenerElement['class'];
|
||||||
|
|
||||||
$listeners[] = array($eventName, $methodName);
|
$metadata->addEntityListener($eventName, $className, $methodName);
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($listenerElement['class'])) {
|
|
||||||
$className = (string) $listenerElement['class'];
|
|
||||||
|
|
||||||
foreach ($listeners as $item) {
|
|
||||||
$metadata->addEntityListener($item[0], $className, $item[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate as lifecycle callback if the listener class is not given.
|
|
||||||
foreach ($listeners as $item) {
|
|
||||||
$metadata->addLifecycleCallback($item[1], $item[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -575,34 +575,12 @@ class YamlDriver extends FileDriver
|
||||||
|
|
||||||
// Evaluate entityListeners
|
// Evaluate entityListeners
|
||||||
if (isset($element['entityListeners'])) {
|
if (isset($element['entityListeners'])) {
|
||||||
foreach ($element['entityListeners'] as $entityListener) {
|
foreach ($element['entityListeners'] as $className => $entityListener) {
|
||||||
$listeners = array();
|
|
||||||
$className = null;
|
|
||||||
|
|
||||||
if (isset($entityListener['class'])) {
|
|
||||||
$className = $entityListener['class'];
|
|
||||||
|
|
||||||
unset($entityListener['class']);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($entityListener as $eventName => $callbackElement){
|
foreach ($entityListener as $eventName => $callbackElement){
|
||||||
foreach ($callbackElement as $methodName){
|
foreach ($callbackElement as $methodName){
|
||||||
$listeners[] = array($eventName, $methodName);
|
$metadata->addEntityListener($eventName, $className, $methodName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $className) {
|
|
||||||
foreach ($listeners as $item){
|
|
||||||
$metadata->addEntityListener($item[0], $className, $item[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate as lifecycle callback if the listener class is not given.
|
|
||||||
foreach ($listeners as $item){
|
|
||||||
$metadata->addLifecycleCallback($item[1], $item[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,4 @@ final class EntityListeners implements Annotation
|
||||||
* @var array<string>
|
* @var array<string>
|
||||||
*/
|
*/
|
||||||
public $value = array();
|
public $value = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies the entity lifecycle callbacks.
|
|
||||||
*
|
|
||||||
* @var array<\Doctrine\ORM\Mapping\LifecycleCallback>
|
|
||||||
*/
|
|
||||||
public $callbacks = array();
|
|
||||||
}
|
}
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the MIT license. For more information, see
|
|
||||||
* <http://www.doctrine-project.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Doctrine\ORM\Mapping;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
|
||||||
* @since 2.4
|
|
||||||
*
|
|
||||||
* @Annotation
|
|
||||||
* @Target("ANNOTATION")
|
|
||||||
*/
|
|
||||||
final class LifecycleCallback implements Annotation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $method;
|
|
||||||
}
|
|
|
@ -59,9 +59,6 @@ namespace Doctrine\Tests\Models\CMS;
|
||||||
* )
|
* )
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
* @EntityListeners(callbacks = {
|
|
||||||
* @LifecycleCallback(\Doctrine\ORM\Events::prePersist, method = "prePersistHandler")
|
|
||||||
* })
|
|
||||||
*/
|
*/
|
||||||
class CmsAddress
|
class CmsAddress
|
||||||
{
|
{
|
||||||
|
@ -129,11 +126,6 @@ class CmsAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prePersistHandler($event)
|
|
||||||
{
|
|
||||||
$this->prePersistHandlerCalls[] = $event;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
|
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
$metadata->setPrimaryTable(array(
|
$metadata->setPrimaryTable(array(
|
||||||
|
@ -162,8 +154,6 @@ class CmsAddress
|
||||||
'joinColumns' => array(array('referencedColumnName' => 'id'))
|
'joinColumns' => array(array('referencedColumnName' => 'id'))
|
||||||
));
|
));
|
||||||
|
|
||||||
$metadata->addLifecycleCallback('prePersistHandler', 'prePersist');
|
|
||||||
|
|
||||||
$metadata->addNamedNativeQuery(array (
|
$metadata->addNamedNativeQuery(array (
|
||||||
'name' => 'find-all',
|
'name' => 'find-all',
|
||||||
'query' => 'SELECT id, country, city FROM cms_addresses',
|
'query' => 'SELECT id, country, city FROM cms_addresses',
|
||||||
|
@ -182,7 +172,6 @@ class CmsAddress
|
||||||
'resultSetMapping' => 'mapping-count',
|
'resultSetMapping' => 'mapping-count',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
$metadata->addSqlResultSetMapping(array (
|
$metadata->addSqlResultSetMapping(array (
|
||||||
'name' => 'mapping-find-all',
|
'name' => 'mapping-find-all',
|
||||||
'columns' => array(),
|
'columns' => array(),
|
||||||
|
|
|
@ -11,7 +11,6 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
try {
|
try {
|
||||||
$this->_schemaTool->createSchema(array(
|
$this->_schemaTool->createSchema(array(
|
||||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\EntityListenersLifecycleCallback'),
|
|
||||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackEventArgEntity'),
|
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackEventArgEntity'),
|
||||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'),
|
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'),
|
||||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'),
|
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'),
|
||||||
|
@ -255,29 +254,6 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
$e->calls['postRemoveHandler']
|
$e->calls['postRemoveHandler']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @group DDC-1955
|
|
||||||
*/
|
|
||||||
public function testEventListenersLifecycleCallback()
|
|
||||||
{
|
|
||||||
$e = new EntityListenersLifecycleCallback;
|
|
||||||
$e->value = 'foo';
|
|
||||||
|
|
||||||
$this->_em->persist($e);
|
|
||||||
$this->_em->flush();
|
|
||||||
|
|
||||||
$this->assertCount(2, $e->calls);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Doctrine\ORM\Event\LifecycleEventArgs',
|
|
||||||
$e->calls['prePersistHandler']
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Doctrine\ORM\Event\LifecycleEventArgs',
|
|
||||||
$e->calls['postPersistHandler']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @Entity @HasLifecycleCallbacks */
|
/** @Entity @HasLifecycleCallbacks */
|
||||||
|
@ -406,35 +382,6 @@ class LifecycleListenerPreUpdate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Entity
|
|
||||||
* @EntityListeners(callbacks = {
|
|
||||||
* @LifecycleCallback(\Doctrine\ORM\Events::prePersist, method = "prePersistHandler"),
|
|
||||||
* @LifecycleCallback(\Doctrine\ORM\Events::postPersist, method = "postPersistHandler"),
|
|
||||||
* })
|
|
||||||
*/
|
|
||||||
class EntityListenersLifecycleCallback
|
|
||||||
{
|
|
||||||
/** @Id @Column(type="integer") @GeneratedValue */
|
|
||||||
public $id;
|
|
||||||
|
|
||||||
/** @Column() */
|
|
||||||
public $value;
|
|
||||||
|
|
||||||
public $calls = array();
|
|
||||||
|
|
||||||
public function prePersistHandler($event)
|
|
||||||
{
|
|
||||||
$this->calls[__FUNCTION__] = $event;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postPersistHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event)
|
|
||||||
{
|
|
||||||
$this->calls[__FUNCTION__] = $event;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @Entity @HasLifecycleCallbacks */
|
/** @Entity @HasLifecycleCallbacks */
|
||||||
class LifecycleCallbackEventArgEntity
|
class LifecycleCallbackEventArgEntity
|
||||||
{
|
{
|
||||||
|
|
|
@ -856,21 +856,6 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
|
||||||
$this->assertEmpty($contractListener->postPersistCalls);
|
$this->assertEmpty($contractListener->postPersistCalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group DDC-1955
|
|
||||||
*/
|
|
||||||
public function testEventListenersLifecycleCallback()
|
|
||||||
{
|
|
||||||
$em = $this->_getTestEntityManager();
|
|
||||||
$factory = $this->createClassMetadataFactory($em);
|
|
||||||
$metadata = $factory->getMetadataFor('Doctrine\Tests\Models\CMS\CmsAddress');
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('prePersist', $metadata->lifecycleCallbacks);
|
|
||||||
$this->assertCount(1, $metadata->lifecycleCallbacks['prePersist']);
|
|
||||||
$this->assertEquals('prePersistHandler', $metadata->lifecycleCallbacks['prePersist'][0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,12 +21,6 @@
|
||||||
</named-native-query>
|
</named-native-query>
|
||||||
</named-native-queries>
|
</named-native-queries>
|
||||||
|
|
||||||
<entity-listeners>
|
|
||||||
<entity-listener>
|
|
||||||
<lifecycle-callback type="prePersist" method="prePersistHandler"/>
|
|
||||||
</entity-listener>
|
|
||||||
</entity-listeners>
|
|
||||||
|
|
||||||
<sql-result-set-mappings>
|
<sql-result-set-mappings>
|
||||||
<sql-result-set-mapping name="mapping-find-all">
|
<sql-result-set-mapping name="mapping-find-all">
|
||||||
<entity-result entity-class="CmsAddress">
|
<entity-result entity-class="CmsAddress">
|
||||||
|
|
|
@ -14,10 +14,6 @@ Doctrine\Tests\Models\CMS\CmsAddress:
|
||||||
resultSetMapping: mapping-count
|
resultSetMapping: mapping-count
|
||||||
query: SELECT COUNT(*) AS count FROM cms_addresses
|
query: SELECT COUNT(*) AS count FROM cms_addresses
|
||||||
|
|
||||||
entityListeners:
|
|
||||||
listener[0]:
|
|
||||||
prePersist: [prePersistHandler]
|
|
||||||
|
|
||||||
sqlResultSetMappings:
|
sqlResultSetMappings:
|
||||||
mapping-find-all:
|
mapping-find-all:
|
||||||
entityResult:
|
entityResult:
|
||||||
|
|
|
@ -8,8 +8,7 @@ Doctrine\Tests\Models\Company\CompanyContract:
|
||||||
flexultra: CompanyFlexUltraContract
|
flexultra: CompanyFlexUltraContract
|
||||||
|
|
||||||
entityListeners:
|
entityListeners:
|
||||||
listener[0]:
|
CompanyContractListener:
|
||||||
class : CompanyContractListener
|
|
||||||
|
|
||||||
preFlush: [preFlushHandler]
|
preFlush: [preFlushHandler]
|
||||||
postLoad: [postLoadHandler]
|
postLoad: [postLoadHandler]
|
||||||
|
|
|
@ -2,8 +2,7 @@ Doctrine\Tests\Models\Company\CompanyFlexUltraContract:
|
||||||
type: entity
|
type: entity
|
||||||
|
|
||||||
entityListeners:
|
entityListeners:
|
||||||
listener[0]:
|
CompanyContractListener:
|
||||||
class : CompanyContractListener
|
|
||||||
|
|
||||||
preFlush: [preFlushHandler]
|
preFlush: [preFlushHandler]
|
||||||
postLoad: [postLoadHandler]
|
postLoad: [postLoadHandler]
|
||||||
|
@ -17,8 +16,7 @@ Doctrine\Tests\Models\Company\CompanyFlexUltraContract:
|
||||||
postRemove: [postRemoveHandler]
|
postRemove: [postRemoveHandler]
|
||||||
preRemove: [preRemoveHandler]
|
preRemove: [preRemoveHandler]
|
||||||
|
|
||||||
listener[1]:
|
CompanyFlexUltraContractListener:
|
||||||
class : CompanyFlexUltraContractListener
|
|
||||||
|
|
||||||
prePersist: [prePersistHandler1, prePersistHandler2]
|
prePersist: [prePersistHandler1, prePersistHandler2]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue