Download the PHP package hostnet/entity-revision-component without Composer
On this page you can find all versions of the php package hostnet/entity-revision-component. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hostnet/entity-revision-component
More information about hostnet/entity-revision-component
Files in hostnet/entity-revision-component
Package entity-revision-component
Short Description Listens to an event so revisions can be made
License MIT
Informations about the package entity-revision-component
README
- What is the Revision Component?
- Requirements
- Installation
Documentation
- How does it work?
- Setup
- Registering the Events
- Creating a Revision Entity
- Configuring the Entity
- Creating the AcmeRevisionFactory
- What's Next?
What is the Entity Revision Component?
The Entity Revision Component is a library that utilizes the Entity Tracker Component and lets you hook in to the entityChanged event.
This component lets you automatically store revisions for a set of entities per flush.
Requirements
The revision component requires a minimum of php 7.3 and runs on Doctrine2. For specific requirements, please check composer.json.
Installation
Installing is pretty easy, this package is available on packagist. You can register the package locked to a major as we follow Semantic Versioning 2.0.0.
Example
Note: You can use dev-master if you want the latest changes, but this is not recommended for production code!
Documentation
How does it work?
It works by putting the @Revision
annotation and RevisionableInterface on your Entity and registering the listener on the entityChanged event, assuming you have already configured the Entity Tracker Component.
For a usage example, follow the setup below.
Note: this component works very well with the Entity Mutation Component. This combination is ideal to go back in time based on revisions.
Setup
- You have to add
@Revision
to your entity - You have to add the RevisionableInterface to your entity
- You need a Revision Entity
Registering the events
Here's an example of a very basic setup. Setting this up will be a lot easier if you use a framework that has a Dependency Injection Container.
It might look a bit complicated to set up, but it's pretty much setting up the tracker component for the most part. If you use it in a framework, it's recommended to create a framework specific configuration package for this to automate this away.
Note: If you use Symfony2, you can take a look at the hostnet/entity-tracker-bundle. This bundle is designed to configure the services for you.
Note: The RevisionListener must be registered on both the onFlush and entityChanged. Because the revisions are grouped per flush, you must also make sure that the RevisionListener is registered before the EntityChangedListener. If this is not done, you will recieve unexpected results.
Creating a Revision Entity
Revisions are stored in the database, thus need an Entity. You're free to decide how to store it but you should implement the RevisionInterface on it.
Configuring the Entity
All we have to do now is put the @Revision
annotation and RevisionableInterface on our Entity.
Creating the AcmeRevisionFactory
The factory is responsible for providing a revision Entity. You're free to fill in what you want and not obligated to using a constructor like in this example. The only requirement is that it creates a Revision.
What's next?
All you have to do now is change multiple entities with @Revision
and they will be grouped by a Revision Entity.
All versions of entity-revision-component with dependencies
doctrine/orm Version ^2.4.0
hostnet/entity-tracker-component Version ^1.2.0||^2.0.0
psr/log Version ^1.0.0