Hector ORM

Hector ORM is the default and recommended ORM for Berlioz Framework. The berlioz/hector-package provides seamless integration between the framework and the ORM: automatic configuration, event subscription, cache management, debug console page, and CLI commands.

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",
        "username": "username",
        "password": "password",
        "schemas": [
            "mydbname"
        ]
    }
}

Default configuration is:

{
    "hector": {
        "dsn": null,
        "read_dsn": null,
        "username": null,
        "password": 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(): void called after save (insert/update)
  • Entity::onBeforeSave(): void called before save (insert/update)
  • Entity::onAfterSave(): void called after save (insert/update)

Insert magic methods:

  • Entity::onInsert(): void called after insert
  • Entity::onBeforeInsert(): void called before insert
  • Entity::onAfterInsert(): void called after insert

Update magic methods:

  • Entity::onUpdate(): void called after update
  • Entity::onBeforeUpdate(): void called before update
  • Entity::onAfterUpdate(): void called after update

Delete magic methods:

  • Entity::onDelete(): void called after delete
  • Entity::onBeforeDelete(): void called before delete
  • Entity::onAfterDelete(): void called after delete

All methods are called from service container, so the dependency injection is enabled :).

CLI commands

The Hector package registers the following CLI commands:

hector:cache-clear

Clear the Hector ORM cache.

$ vendor/bin/berlioz hector:cache-clear

hector:generate-schema

Generate the schema for Hector ORM entities. This command initializes the ORM and triggers schema generation.

$ vendor/bin/berlioz hector:generate-schema

Last updated: Wed, 18 Feb 2026 11:34