[PR #423] [MERGED] DDC-1955 - @EntityListeners #8173

Open
opened 2026-01-22 15:58:44 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/423
Author: @FabioBatSilva
Created: 8/12/2012
Status: Merged
Merged: 2/2/2013
Merged by: @beberlei

Base: masterHead: DDC-1955


📝 Commits (10+)

  • 368cf73 entity listeners mapping
  • 0f081d7 support short class name
  • 3c223a5 move call listeners tests to AbstractMappingDriverTest
  • c5d59ab test entity listener metadata
  • ccc0a2a test entity listener calls
  • 315f7ba call listeners in UoW
  • dbd0697 test @PostLoad
  • c6adcda give event to lifecycle callbacks
  • 4cfe229 test lifecycle callbacks event args
  • 6be7a03 fix previous test

📊 Changes

46 files changed (+2162 additions, -164 deletions)

View changed files

📝 docs/en/reference/events.rst (+227 -3)
📝 doctrine-mapping.xsd (+16 -0)
📝 lib/Doctrine/ORM/Configuration.php (+28 -0)
lib/Doctrine/ORM/Event/ListenersInvoker.php (+120 -0)
lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php (+72 -0)
📝 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php (+5 -1)
📝 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (+57 -23)
lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php (+75 -0)
📝 lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (+86 -45)
📝 lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php (+1 -0)
📝 lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php (+25 -4)
📝 lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php (+19 -0)
lib/Doctrine/ORM/Mapping/EntityListenerResolver.php (+55 -0)
lib/Doctrine/ORM/Mapping/EntityListeners.php (+41 -0)
📝 lib/Doctrine/ORM/Mapping/MappingException.php (+23 -0)
📝 lib/Doctrine/ORM/UnitOfWork.php (+56 -78)
📝 tests/Doctrine/Tests/Models/CMS/CmsAddress.php (+35 -1)
tests/Doctrine/Tests/Models/CMS/CmsAddressListener.php (+58 -0)
📝 tests/Doctrine/Tests/Models/Company/CompanyContract.php (+41 -0)
tests/Doctrine/Tests/Models/Company/CompanyContractListener.php (+84 -0)

...and 26 more files

📄 Description

http://www.doctrine-project.org/jira/browse/DDC-1955

Hi.

This path adds support for @EntityListeners

This path add another way to handle events
allow configure the same listener for many specific entities.
And give the EventArg in the current lifecycle callback system.

Usage :

<?php
/**
 * @EntityListeners({"ContractListener"})
 * @HasLifecycleCallbacks
 * @Entity  
 */
class Contract
{
    /** @PostLoad */
    public function postLoadHandler(LifecycleEventArgs $event)
    {
        // do something
    }
}
class ContractListener
{
    /** @PrePersist  */
    public function prePersistHandler(Contract $contract)
    {
        // do something
    }
    /**
     * @PostPersist
     * Most of cases just the entity is needed.
     * as a second parameter LifecycleEventArgs allow access to the entity manager.
     */
    public function postPersistHandler(Contract $contract, LifecycleEventArgs $args)
    {
        // do something
    }
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/423 **Author:** [@FabioBatSilva](https://github.com/FabioBatSilva) **Created:** 8/12/2012 **Status:** ✅ Merged **Merged:** 2/2/2013 **Merged by:** [@beberlei](https://github.com/beberlei) **Base:** `master` ← **Head:** `DDC-1955` --- ### 📝 Commits (10+) - [`368cf73`](https://github.com/doctrine/orm/commit/368cf73f892e266fce695bb3e2ab8a75aa603bc9) entity listeners mapping - [`0f081d7`](https://github.com/doctrine/orm/commit/0f081d7c4525b51f577a753173f7ba9dd00350b6) support short class name - [`3c223a5`](https://github.com/doctrine/orm/commit/3c223a59c407610db94b1d5ad16916b72eabdd5c) move call listeners tests to AbstractMappingDriverTest - [`c5d59ab`](https://github.com/doctrine/orm/commit/c5d59ab4c797ac079da1169799ac8729ff259335) test entity listener metadata - [`ccc0a2a`](https://github.com/doctrine/orm/commit/ccc0a2a94f4ee01fa155fc68bb1e4608d5c29088) test entity listener calls - [`315f7ba`](https://github.com/doctrine/orm/commit/315f7ba43b9c2226c9d801142ade87c4f5a8f56a) call listeners in UoW - [`dbd0697`](https://github.com/doctrine/orm/commit/dbd0697c2ced66adc6e4319ac8de7e8e466cc2ab) test @PostLoad - [`c6adcda`](https://github.com/doctrine/orm/commit/c6adcda5675036debad35d2ae6df968b458bd4bc) give event to lifecycle callbacks - [`4cfe229`](https://github.com/doctrine/orm/commit/4cfe2294e3d789688483cb56c1012543e0f758b4) test lifecycle callbacks event args - [`6be7a03`](https://github.com/doctrine/orm/commit/6be7a03b72607f5834b11d9896a9f74ce6334a59) fix previous test ### 📊 Changes **46 files changed** (+2162 additions, -164 deletions) <details> <summary>View changed files</summary> 📝 `docs/en/reference/events.rst` (+227 -3) 📝 `doctrine-mapping.xsd` (+16 -0) 📝 `lib/Doctrine/ORM/Configuration.php` (+28 -0) ➕ `lib/Doctrine/ORM/Event/ListenersInvoker.php` (+120 -0) ➕ `lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php` (+72 -0) 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php` (+5 -1) 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php` (+57 -23) ➕ `lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php` (+75 -0) 📝 `lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php` (+86 -45) 📝 `lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php` (+1 -0) 📝 `lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php` (+25 -4) 📝 `lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php` (+19 -0) ➕ `lib/Doctrine/ORM/Mapping/EntityListenerResolver.php` (+55 -0) ➕ `lib/Doctrine/ORM/Mapping/EntityListeners.php` (+41 -0) 📝 `lib/Doctrine/ORM/Mapping/MappingException.php` (+23 -0) 📝 `lib/Doctrine/ORM/UnitOfWork.php` (+56 -78) 📝 `tests/Doctrine/Tests/Models/CMS/CmsAddress.php` (+35 -1) ➕ `tests/Doctrine/Tests/Models/CMS/CmsAddressListener.php` (+58 -0) 📝 `tests/Doctrine/Tests/Models/Company/CompanyContract.php` (+41 -0) ➕ `tests/Doctrine/Tests/Models/Company/CompanyContractListener.php` (+84 -0) _...and 26 more files_ </details> ### 📄 Description http://www.doctrine-project.org/jira/browse/DDC-1955 Hi. This path adds support for `@EntityListeners` This path add another way to handle events allow configure the same listener for many specific entities. And give the EventArg in the current lifecycle callback system. Usage : ``` php <?php /** * @EntityListeners({"ContractListener"}) * @HasLifecycleCallbacks * @Entity */ class Contract { /** @PostLoad */ public function postLoadHandler(LifecycleEventArgs $event) { // do something } } class ContractListener { /** @PrePersist */ public function prePersistHandler(Contract $contract) { // do something } /** * @PostPersist * Most of cases just the entity is needed. * as a second parameter LifecycleEventArgs allow access to the entity manager. */ public function postPersistHandler(Contract $contract, LifecycleEventArgs $args) { // do something } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 15:58:44 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#8173