Hector ORM

Hector ORM is a lightweight, framework-agnostic PHP ORM — designed to be modular, fast, and expressive.

Get started Source code
$ composer require hectororm/orm

Getting Started 🚀

Introduction

Hector ORM is a lightweight, framework-agnostic PHP ORM — designed to be modular, fast, and expressive. It draws inspiration from existing ORM concepts, while promoting freedom of structure and strong typing.

What is an ORM?

Object-relational mapping (ORM, O/RM, and O/R mapping tool!) in computer science is a programming technique for converting data between incompatible type systems using object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language.

Wikipedia

Choose Your Style ✨

You can manage entities in multiple ways:

  • Classic entities: define PHP properties explicitly and Hector ORM handles mapping.
  • Magic entities: rely on Hector ORM dynamic behavior using PHP’s magic methods.
  • Roll your own 🧪: create a custom Mapper if you want total control over mapping logic.

Quick Start

1. Installation 📦

Install with Composer:

composer require hectororm/hectororm

2. Create a Database Connection

use Hector\Connection\Connection;

$connection = new Connection('mysql:host=localhost;dbname=test', 'user', 'pass');

3. Boot the ORM

use Hector\Orm\OrmFactory;

$orm = OrmFactory::orm([
    'schemas' => ['my-schema']
], $connection);

4. Define Entities 🧱

use Hector\Orm\Attributes as Orm;
use Hector\Orm\Entity\MagicEntity;

#[Orm\HasOne(Bar::class, 'bar')]
class Foo extends MagicEntity {}

#[Orm\BelongsTo(Foo::class, 'foo')]
class Bar {}

5. Use the ORM 💡

$foo = Foo::findOrFail(1); // find a Foo entity by primary key
$bar = $foo->bar; // access related Bar entity

echo $bar->field; // access a field from the related Bar

You’re now ready to build with Hector ORM. Keep exploring:

Happy mapping 🗺️

Last updated: Wed, 17 Sep 2025 12:38