multibytesystems / mb-components
Helper library to provide base functionality to common tasks when dealing with data driven applications
Requires
- php: >=5.3.0
- doctrine/dbal: ~2.5
- doctrine/orm: ~2.5
This package is not auto-updated.
Last update: 2024-11-10 05:46:04 UTC
README
This Zend module provides base classes to simplify handling of doctrine entities. Currently it consists of
- two abstract entity classes
- one general repository class
- one service class
Install
composer require multibytesystems/mb-components
Entity classes
-
MBBaseEntity
simplifies handling of creation and modification date by providing acreated
and amodified
property along with its accessor methods as well as appropriate lifecycleevent methods to set creation and modification date on persist and modification date on update. So this has not to be implemented in every entity class on it's own. In addition this class defines an abstract classgetTextIdentifier()
that is very similar to angetString()
method and that should return a suitable string representation of the entity. -
MBInterleavedChecksumEntity
creates a simple checksum from provided record data as well as an interleaved checksum from provided record data alongside with data of the forerunning record (the predecessor). It defines an abstract methodgetInterityData()
that needs to be implemented in the concrete entity class and returns an array of data that should be included within the checksum. This class also saves the id of it's predecessor into the current record.
Repository class
MBInterleavedChecksumEntityRepository
provides thefindLatest()
method that returns the latest record within the corresponding table. Currently it does this by id (what means that this only works as intended if id is incremental).
Service class
IntegrityService
provides thegetValidatedEntities()
method that returns a list of all entities with their validity checked. This result is similar to the repository's methodfindAll()
but with validation and is needed as validation is a tiime consuming process and should not happen on every findAll()` operation.
Usage
To use MBBaseEntity
add the following fields to the table that is related to the entity.
created (DateTime)
modified (DateTime)
Extend the MBBaseEntity
within the concrete entity class. Add a getTextIdentifier()
method to the concrete class that returns a suitable string representation of the entity.
To use MBInterleavedChecksumEntityRepository
do everything that has to be done for using MBBaseEntity
(this is because MBInterleavedChecksumEntityRepository
extends MBBaseEntity
) and add the following fields to the table that is related to the entity.
simple_checksum (varchar(1000))
interleaved_checksum (varchar(1000))
predecessor_id (int)
Extend the MBInterleavedChecksumEntityRepository
within the concrete entity class. Add a getInterityData()
method to the concrete class that returns an array of data that should be part of the simple and interleaved checksum.