Download the PHP package t4web/infrastructure without Composer
On this page you can find all versions of the php package t4web/infrastructure. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package infrastructure
Infrastructure
Infrastructure layer for Domain, implementation by t4web\domain-interface
Contents
- Installation
- Quick start
- Components
- Build criteria from array
- Configuring
- Events
Installation
Add this project in your composer.json:
Now tell composer to download Domain by running the command:
Quick start
You can use Repository
with Domain implementation t4web\domain.
This implementation build on Zend\Db and
Zend\EventManager
Components
-
Criteria
- for creating fetch expression -
CriteriaFactory
- for creating complex criteria from array -
Mapper
- for translateEntity
to table row (array), and filter table row accordingcolumnsAsAttributesMap
-
QueryBuilder
- for build SQL query Repository
- for store entities and restore from storage
Build criteria from array
You can use CriteriaFactory::build()
for building criteria from array (for example:
from input filter, post\get request)
$inputData
must be structured like this:
where ATTRIBUTE
- criteria field, METHOD
- one of equalTo
, notEqualTo
, lessThan
,
greaterThan
, greaterThanOrEqualTo
, lessThanOrEqualTo
, like
, in
for isNull
, isNotNull
use
where TRUE_EXPRESSION
can be any true expression: true
, 1
, 'a'
etc.
for between
use array as value
for limit
, offset
use
for order
use SQL-like order expression
Custom criteria - grouping and reusing criteria
Users\User\Criteria\Active
- must be invokable class (__invoke(CriteriaInterface $criteria, $value)
)
Configuring
For configuring Repository
you must specify config, and use Config
object for parsing config. QueryBuilder
use Config
for building SQL query.
relations
argument order - very important, Task['relations']['User'][0]
- must be field from current entity, Task['relations']['User'][1]
- must be field from related entity.
For many-to-many relation related entity must contain 3 arguments. For example we have table tasks
(see config), table tags
with fields id
, name
and table tasks_tags_link
with fields task_id
and tag_id
. For relation Task <=> Tag we must describe many-to-many relation: Task['relations']['Tag'][0]
- link-table name, Task['relations']['Tag'][1]
- field PK current entity in link-table and Task['relations']['Tag'][2]
- field PK in related entity in link-table.
Events
Repository
rise events when entity created or updated.
Where REPOSITORY_IDENTIFIER
- depends from entity, builds: EntityName\Infrastructure\Repository
ENTITY_CLASS
- get_class() from you $enity object
Now Repository
can rise:
entity:ModuleName\EntityName\EntityName:created
- rise after Entity just created in DB. In context event subscriber receive Zend\EventManager\Event.entity:ModuleName\EntityName\EntityName:changed:pre
- rise before Entity update in DB. In context event subscriber receive T4webInfrastructure\Event\EntityChangedEvent.entity:ModuleName\EntityName\EntityName:changed
- rise after Entity just updated in DB. In context event subscriber receive T4webInfrastructure\Event\EntityChangedEvent.attribute:ModuleName\EntityName\EntityName:attribute:changed
- rise after Entity attribute updated in DB. In context event subscriber receive T4webInfrastructure\Event\EntityChangedEvent.
All versions of infrastructure with dependencies
zendframework/zend-db Version <2.6 >=2.4
zendframework/zend-eventmanager Version <2.6 >=2.4
t4web/domain-interface Version ~1.1.0