Hector ORM
A Berlioz package exist for Hector ORM library to easier the interactions and configuration between them.
Installation
Use composer to install package:
composer require berlioz/hector-package
For more detail package installation, referred to the package description page.
Configuration
Create a hector.json file in your configuration directory, with this content:
{
"hector": {
"dsn": "mysql:dbname=mydbname;host=127.0.0.1;port=3306;charset=UTF8;user=username;password=password",
"schemas": [
"mydbname"
]
}
}
Default configuration is:
{
"hector": {
"dsn": null,
"read_dsn": null,
"schemas": [],
"dynamic_events": true,
"types": []
}
}
Ignore this configuration file in your .gitignore file. It should contain passwords… and MUST NOT push on GIT
repository!
Package additions
- Subscription of ORM events with framework event manager
- Debug page in console
- Not found entities exception generate a not found http error
- Usage of cache system of framework
- Magics methods in entities to manage events simply
Usage
To know more on usage with the ORM, referrer you to the official documentation of Hector ORM.
Events magic methods
Save magic methods:
Entity::onSave(): voidcalled after save (insert/update)Entity::onBeforeSave(): voidcalled before save (insert/update)Entity::onAfterSave(): voidcalled after save (insert/update)
Insert magic methods:
Entity::onInsert(): voidcalled after insertEntity::onBeforeInsert(): voidcalled before insertEntity::onAfterInsert(): voidcalled after insert
Update magic methods:
Entity::onUpdate(): voidcalled after updateEntity::onBeforeUpdate(): voidcalled before updateEntity::onAfterUpdate(): voidcalled after update
Delete magic methods:
Entity::onDelete(): voidcalled after deleteEntity::onBeforeDelete(): voidcalled before deleteEntity::onAfterDelete(): voidcalled after delete
All methods are called from service container, so the dependency injection is enabled :).