Hector ORM

Hector ORM β€” lightweight PHP ORM with zero-config mapping, lazy relationships, and full typing. Framework-agnostic.

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.

Requirements

  • PHP 8.0+
  • PDO extension
  • Database driver (e.g., pdo_mysql, pdo_sqlite)

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.

Why Hector ORM?

Feature Hector ORM Doctrine Eloquent
Zero config βœ… ❌ ⚠️
Framework-agnostic βœ… βœ… ❌
Magic + Classic entities βœ… ❌ βœ…
Schema introspection βœ… ❌ ❌

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'] // Database name(s) to introspect
], $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 extends MagicEntity {}

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: Thu, 22 Jan 2026 14:17