Download the PHP package tarasmatskovich/house-orm without Composer
On this page you can find all versions of the php package tarasmatskovich/house-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package house-orm
House ORM
House ORM is a simply PHP object relationship mapping library for wotk with data in database.
Available drivers
- Memory (for test environment)
- MySQL
Installing
Usage
For example in datatabase exists table users with fields id, name. You have to create corresponding entity Class and specify fields mapping:
Important part of entity class is docs annotations. It uses for mapping specifing First required type of entity annotations is Gateway in format.
For example if you have table in database named users you have to write:
Second type of entity annotations is Field
You should specify this annotation on entity class field which want to map:
Then you have to create repository (mapper) class for work with corresponding entity wich extends houseorm/mapper/DomainMapper class. Lets continue exmple with users:
Then you should to register this repository (mapper) in entity manager. This is config params:
House ORM have two drivers. First for real with real mysql database:
Second for tests (All data will be save on PHP proccess memory and you do not need real database):
Creating entity manager and register UserRepository and User entity:
Then you can get access to repository:
Find
To find user entity with primary key (default id
):
Also you can find entity through criteria
Save
To save new entity you have to create new object of entity class, fill fields and save through repository:
Update
To update entity you may change some fields and save entity object through repository:
Delete
To delete entity:
Relations
For specifying relations you have to use special annotations. Exist two types of relations:
- Simple relation (for example table
comments
have fielduser_id
which directly related with tableusers
and fieldid
) - Complicated relation wich need one more binding table (for exampe exist tables
users
,roles
, and binding tableuser_roles
which have binding fieldsuser_id
androle_id
which related with fieldsid
inusers
androles
tables corresponding)
Simple relations
Specifying by special annotation Relation
. This is our example with users. User entity class:
And new entity Comment class:
Complicated relations
To specify complicated relations you have to use special annotation ViaRelation
Example - entity Role
related with User
through binding entity UserRole
User entity class:
UserRole entity:
Role entity class:
Cache
You can use cache to increase performance of ORM work. House ORM support two drivers of cache:
- Memory cache (usefull for async php)
- Redis cache Usage memory cache:
Usage Redis cache:
All versions of house-orm with dependencies
ext-json Version *
ext-pdo Version *
tarasmatskovich/annotations Version ^1.9
psr/log Version ^1.1
predis/predis Version ^1.1