Download the PHP package hostnet/entity-blamable-component without Composer
On this page you can find all versions of the php package hostnet/entity-blamable-component. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hostnet/entity-blamable-component
More information about hostnet/entity-blamable-component
Files in hostnet/entity-blamable-component
Package entity-blamable-component
Short Description Listens to an event so auditable information can be set
License MIT
Informations about the package entity-blamable-component
README
- What is the Entity Blamable?
- Requirements
- Installation
Documentation
- How does it work?
- Setup
- Registering the Events
- Creating a Provider for the Username and Timestamp
- Configuring the Entity
- What's Next?
What is the Entity Blamable Component?
The Entity Blamable Component is a library that utilizes the Entity Tracker Component and lets you hook in to the entityChanged event.
This component lets you automatically update entities by implementing setUpdatedAt()
, setUpdatedBy
and setCreatedAt()
. At the given time, you have to implement all of them. If you need only 1 or 2 of the methods, pull requests are always allowed. It's not implemented yet due to lack of requirements for our use-cases.
Requirements
The blamable component requires a minimum of php 5.4 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 @Blamable
annotation and BlamableInterface 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.
Setup
- You have to add
@Blamable
to your entity - You have to add the BlamableInterface to your entity
- You have to implement the BlamableProviderInterface on an object and pass it to the listener
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.
Creating a Provider for the Username and Timestamp
The provider is used to feed the required values to the BlamableListener, this is the only interface that requires a custom implementation in your project.
Note that in the example the username is defined as constructor param, but you might want to inject something that contains the currently logged in user and get that identifier.
Configuring the Entity
All we have to do now is put the @Blamable
annotation and BlamableInterface on our Entity.
What's next?
All versions of entity-blamable-component with dependencies
doctrine/orm Version ^2.4.0
hostnet/entity-tracker-component Version ^1.2.0||^2.0.0