1
0
mirror of synced 2024-12-05 03:06:05 +03:00

remove @LifecycleCallback

This commit is contained in:
Fabio B. Silva 2012-10-06 18:13:51 -03:00 committed by fabio.silva
parent ffc8d032c7
commit c60e3e4ba4
14 changed files with 13 additions and 199 deletions

View File

@ -51,6 +51,7 @@
<xs:enumeration value="preRemove"/>
<xs:enumeration value="postRemove"/>
<xs:enumeration value="postLoad"/>
<xs:enumeration value="preFlush"/>
</xs:restriction>
</xs:simpleType>

View File

@ -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

View File

@ -64,5 +64,4 @@ require_once __DIR__.'/../AssociationOverride.php';
require_once __DIR__.'/../AssociationOverrides.php';
require_once __DIR__.'/../AttributeOverride.php';
require_once __DIR__.'/../AttributeOverrides.php';
require_once __DIR__.'/../EntityListeners.php';
require_once __DIR__.'/../LifecycleCallback.php';
require_once __DIR__.'/../EntityListeners.php';

View File

@ -19,10 +19,10 @@
namespace Doctrine\ORM\Mapping\Driver;
use SimpleXMLElement,
Doctrine\Common\Persistence\Mapping\Driver\FileDriver,
Doctrine\Common\Persistence\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\MappingException;
use SimpleXMLElement;
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
/**
* XmlDriver is a metadata driver that enables mapping through XML files.
@ -560,28 +560,12 @@ class XmlDriver extends FileDriver
// Evaluate entity listener
if (isset($xmlRoot->{'entity-listeners'})) {
foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) {
$listeners = array();
foreach ($listenerElement as $callbackElement) {
$eventName = (string) $callbackElement['type'];
$methodName = (string) $callbackElement['method'];
$className = (string) $listenerElement['class'];
$listeners[] = array($eventName, $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]);
$metadata->addEntityListener($eventName, $className, $methodName);
}
}
}

View File

@ -575,34 +575,12 @@ class YamlDriver extends FileDriver
// Evaluate entityListeners
if (isset($element['entityListeners'])) {
foreach ($element['entityListeners'] as $entityListener) {
$listeners = array();
$className = null;
if (isset($entityListener['class'])) {
$className = $entityListener['class'];
unset($entityListener['class']);
}
foreach ($element['entityListeners'] as $className => $entityListener) {
foreach ($entityListener as $eventName => $callbackElement){
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]);
}
}
}
}

View File

@ -38,11 +38,4 @@ final class EntityListeners implements Annotation
* @var array<string>
*/
public $value = array();
/**
* Specifies the entity lifecycle callbacks.
*
* @var array<\Doctrine\ORM\Mapping\LifecycleCallback>
*/
public $callbacks = array();
}

View File

@ -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;
}

View File

@ -59,9 +59,6 @@ namespace Doctrine\Tests\Models\CMS;
* )
* })
*
* @EntityListeners(callbacks = {
* @LifecycleCallback(\Doctrine\ORM\Events::prePersist, method = "prePersistHandler")
* })
*/
class CmsAddress
{
@ -129,11 +126,6 @@ class CmsAddress
}
}
public function prePersistHandler($event)
{
$this->prePersistHandlerCalls[] = $event;
}
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->setPrimaryTable(array(
@ -162,8 +154,6 @@ class CmsAddress
'joinColumns' => array(array('referencedColumnName' => 'id'))
));
$metadata->addLifecycleCallback('prePersistHandler', 'prePersist');
$metadata->addNamedNativeQuery(array (
'name' => 'find-all',
'query' => 'SELECT id, country, city FROM cms_addresses',
@ -182,7 +172,6 @@ class CmsAddress
'resultSetMapping' => 'mapping-count',
));
$metadata->addSqlResultSetMapping(array (
'name' => 'mapping-find-all',
'columns' => array(),

View File

@ -11,7 +11,6 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
parent::setUp();
try {
$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\LifecycleCallbackTestEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'),
@ -255,29 +254,6 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
$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 */
@ -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 */
class LifecycleCallbackEventArgEntity
{

View File

@ -856,21 +856,6 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$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]);
}
}
/**

View File

@ -21,12 +21,6 @@
</named-native-query>
</named-native-queries>
<entity-listeners>
<entity-listener>
<lifecycle-callback type="prePersist" method="prePersistHandler"/>
</entity-listener>
</entity-listeners>
<sql-result-set-mappings>
<sql-result-set-mapping name="mapping-find-all">
<entity-result entity-class="CmsAddress">

View File

@ -14,10 +14,6 @@ Doctrine\Tests\Models\CMS\CmsAddress:
resultSetMapping: mapping-count
query: SELECT COUNT(*) AS count FROM cms_addresses
entityListeners:
listener[0]:
prePersist: [prePersistHandler]
sqlResultSetMappings:
mapping-find-all:
entityResult:

View File

@ -8,8 +8,7 @@ Doctrine\Tests\Models\Company\CompanyContract:
flexultra: CompanyFlexUltraContract
entityListeners:
listener[0]:
class : CompanyContractListener
CompanyContractListener:
preFlush: [preFlushHandler]
postLoad: [postLoadHandler]

View File

@ -2,8 +2,7 @@ Doctrine\Tests\Models\Company\CompanyFlexUltraContract:
type: entity
entityListeners:
listener[0]:
class : CompanyContractListener
CompanyContractListener:
preFlush: [preFlushHandler]
postLoad: [postLoadHandler]
@ -17,8 +16,7 @@ Doctrine\Tests\Models\Company\CompanyFlexUltraContract:
postRemove: [postRemoveHandler]
preRemove: [preRemoveHandler]
listener[1]:
class : CompanyFlexUltraContractListener
CompanyFlexUltraContractListener:
prePersist: [prePersistHandler1, prePersistHandler2]