PHPackages                             w3c/lifecycle-events-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. w3c/lifecycle-events-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

w3c/lifecycle-events-bundle
===========================

A Symfony bundle to dispatch usable entity lifecycle events (create, update, delete)

v5.0.1(8mo ago)189.2k↓50%3W3CPHPPHP &gt;=8.2CI passing

Since Feb 28Pushed 8mo ago9 watchersCompare

[ Source](https://github.com/w3c/W3CLifecycleEventsBundle)[ Packagist](https://packagist.org/packages/w3c/lifecycle-events-bundle)[ Docs](https://github.com/w3c/W3CLifecycleEventsBundle)[ RSS](/packages/w3c-lifecycle-events-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (24)Used By (0)

[![Build Status](https://github.com/w3c/W3CLifecycleEventsBundle/actions/workflows/symfony.yml/badge.svg)](https://github.com/w3c/W3CLifecycleEventsBundle/actions/workflows/symfony.yml)[![Coverage Status](https://camo.githubusercontent.com/12e01d50506817f50774e08c4be21bc23bf9edbd7ec52445c546f4341d1c692b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7733632f5733434c6966656379636c654576656e747342756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/w3c/W3CLifecycleEventsBundle?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/ca353b43b92ab9c13f8c69eb79e52143e6607b61f08a9f0ddf33707363443631/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f62306431343933632d366465382d346331382d383761642d6131326432343837666435392f6d696e692e737667)](https://insight.symfony.com/account/widget?project=b0d1493c-6de8-4c18-87ad-a12d2487fd59)

lifecycle-events-bundle
=======================

[](#lifecycle-events-bundle)

This Symfony bundle is meant to capture and dispatch events that happen throughout the lifecycle of entities:

- creation
- deletion
- updates

Doctrine already provides such events, but using them directly has a few shortcomings:

- You don't decide at which point in a action you want to dispatch events. Events are fired during a flush.
- When Doctrine events are fired, you are not assured that the entities have actually been saved in the database. This is obvious for preUpdate (sent before persisting the changes), but postPersist and preRemove have the same issue: if you persist two new entities in a single transaction, the first insert could work (thus an event would be sent) but not the second, resulting in no entities being saved at all

This bundle aims at circumventing these issues by providing means to fire entity creation, deletion and update events after a successful flush or whenever needed.

It also provides a set of attributes to configure what events should be sent and when.

This bundle was partially inspired by @kriswallsmith's talk ["Matters of State"](https://www.youtube.com/watch?v=lEiwP4w6mf4).

Installation
------------

[](#installation)

Simply run assuming you have installed composer.phar or composer binary:

```
$ php composer.phar require w3c/lifecycle-events-bundle 1.0.*
```

Finally, enable the bundle in the kernel:

```
