Download the PHP package hostnet/entity-tracker-component without Composer

On this page you can find all versions of the php package hostnet/entity-tracker-component. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package entity-tracker-component

README

Documentation

What is the Entity Tracker?

The Entity Tracker Component is a library used to track changes within an Entity during a flush of the EntityManager. This makes it possible to do all sorts of things you want to automated during the preFlush event.

Entities become tracked when you implement the @Tracked annotation or a sub-class of @Tracked. You have total control over what happens next and which events you will use to listen to the entityChanged event.

Let's say that every time you flush your User, you want to set when it was updated. By default, you would have to call $user->setUpdatedAt() manually or create a custom listener on preFlush that sets the updated at timestamp. Both are a lot of extra work and you have to write extra code to determine changes. Listening to preFlush will always trigger your listener and you don't want to make a huge if statement nor create a listener for each Entity.

Requirements

The tracker component requires at least 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 an annotation on your Entity and registering your listener on our event, assuming you have already registered our event to doctrine. That's all you need to do to start tracking the Entity so it will be available in the entityChanged event.

Setup

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.

Note: If you use Symfony, you can take a look at the hostnet/entity-tracker-bundle. This bundle is designed to configure the services for you.

Creating the Listener

The listener needs to have 1 method that has the same name as the event name. This method will have 1 argument which is the EntityChangedEvent $event. The event contains the used EntityManager, Current Entity, Original (old) Entity and an array of the fields which have been altered -or mutated.

Note: The Doctrine2 Event Manager uses the event name as method name, therefore you should implement the entityChanged method as listed below.

Creating an Interface for the Entity

Additionally to the @Tracked annotation, we want to determine if we can set and updated_at field within our Entity. This can be done by creating the following interface for our Entity.

Registering the Annotation on the Entity

All we have to do now is put the @Tracked annotation and Interface on our Entity and implement the required method

What's Next?

Change the value of a field and flush the Entity. This will trigger the preFlush, which in turn will trigger our listener, which then fires up the entityChanged event.

Extending the Tracker Annotation

You might want to extend the @Tracker annotation. This allows you to add options and additional checks within your listener.

Example Annotation

In the following example, you will see how using a creating a custom annotation works.

Using this annotation will give us specific access to options within our listener. We can now attempt to get this annotation in the listener and we get can call getIgnoredFields(). This example will ignore certain fields for entities using the annotation.

Custom Annotation Resolvers

To obtain the Annotation, we have implemented resolvers. The example below shows how you could implement it yourself.

Custom entityChanged Listener

The listener can now use the resolver to obtain the annotation so possible do something extra when a specific set of fields is changed.


All versions of entity-tracker-component with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
doctrine/annotations Version 1.*,>=1.2.0
doctrine/common Version ^2.13.3|^3.0.0
doctrine/orm Version ^2.7.5
psr/log Version ^1.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hostnet/entity-tracker-component contains the following files

Loading the files please wait ....