PHPackages                             fiseo/orm-library - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fiseo/orm-library

ActiveLibrary[Database &amp; ORM](/categories/database)

fiseo/orm-library
=================

A lightweight and expressive ORM (Object-Relational Mapping) for PHP, designed to simplify database interactions while keeping full control over your queries. Check the github for more information (https://github.com/Fiseo/ORM-Library)

1.2.1(3mo ago)17MITPHPPHP &gt;=8.3

Since Jan 15Pushed 3mo agoCompare

[ Source](https://github.com/Fiseo/ORM-Library)[ Packagist](https://packagist.org/packages/fiseo/orm-library)[ RSS](/packages/fiseo-orm-library/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (6)Used By (0)

ORM-Library
===========

[](#orm-library)

A lightweight and expressive **ORM (Object-Relational Mapping)** for PHP, designed to simplify database interactions.

---

Features
========

[](#features)

- Simple mapping between PHP objects and SQL tables
- Relationship support (`OneToOne`, `OneToMany`, `ManyToMany`)
- PDO compatible
- Lightweight, no heavy dependencies
- Supports CTI Inheritance
- Supports Json conversion

---

❗Rules❗
=======

[](#rules)

- The primary key field should always be named **Id**
- The database storage engine must be **InnoDB**

---

Quick start
===========

[](#quick-start)

Define a connection
-------------------

[](#define-a-connection)

Create the connection at the start of your file

```
use OrmLibrary\DbContext;

DbContext::setter()
    ->user("root")
    ->password("root")
    ->base("your_database_name")
    ->server("your_server_address")
    ->set();
```

Create a repository
-------------------

[](#create-a-repository)

Create a repository to perform your queries by extending the abstract class `EntityRepository`

```
use OrmLibrary\Entity\EntityRepository;

class UserRepository extends EntityRepository
{
    protected static string $entityName = 'User';
    protected static string $entityClass = User::class;

}
```

Create an entity
----------------

[](#create-an-entity)

Create an entity for each of your tables by extending the abstract class `AbstractEntity`
To add a field, create a readonly property of a [field class](#fields) and initialize it in the constructor.
❗ Do not create an entity for association tables !
❗ Do not declare the **Id** field (done in `AbstractEntity`) !
❗ An error will be thrown if `$entityName` and `$repositoryClass` are not define !

```
class User extends AbstractEntity
{
    protected static string $entityName = 'User';

    protected static string $repositoryClass = UserRepository::class;

    #[AField("Name", false)]
    readonly StringField $name;

    #[AField("FirstName", false)]
    readonly StringField $firstName;

    #[ARelationField("IdCivility", false)]
    readonly EntityField $civility;

    readonly RelationMTM $drivingLicenses;

    public function __construct($id = null){
        parent::__construct($id);

        $this->name = new StringField([$this, 'load']);
        $this->firstName = new StringField([$this, 'load']);

        $this->civility = new EntityField(Civilite::class,[$this, 'load']);

        $this->drivingLicenses = new RelationMTM($this, DrivingLicense::class, User_DrivingLicenseRepository::class);
    }
}
```

Use it
------

[](#use-it)

This saves the data in the database.

```
$p = new User();
$p->name->set('Doe');
$p->firstName->set('Jane');
$p->save();
```

This loads the data from the database.

```
$p = new User(1);
$p->load();
```

This deletes the entity from the database.

```
$p = new User(1)
$p->delete();
```

---

Core Concept
============

[](#core-concept)

Fields
------

[](#fields)

❗**All fields properties should have a `readonly` visibility**❗

Fields represent a field of the database table.
There are 5 field types as of now :

- `StringField`
- `IntField`
- `FloatField`
- `BoolField`
- `DateField`

To add a field in your entity just add a property like this :

```
#[AField("Name", false)]
readonly StringField $name;
```

The attribute `AField()` requires 2 arguments :

- A String : The name of the field in your database.
- A boolean : True if your field allow nullable value, False otherwise.

Now that your property is created, you need to instance it in the constructor.

```
$this->name = new StringField([$this, 'load']);
```

The constructor of the fields requires 1 argument, but 2 optional arguments are available :

- The loader : the first argument will always be the loader of your current entity. It allows lazy loading.
    If you want to disable lazy loading, give an empty `Closure` as this parameter.

```
[$this, 'load'] // The loader
function () {} //An empty Closure
```

- The getter : the second argument is an optional getter. It allows you to personalize the behavior of the getter. ❗**Do not forget to return a value.** ❗

```
function () {
    return $this->value;
};
```

- The setter : the last argument is an optional setter. It allows you to add your own verification in the setter. ❗**Do not forget to set the value.** ❗

```
function ($value) {
    if($value == 'Exemple')
        throw new Exception('This string cannot be equal to "Exemple"')
    $this->value = $value;
};
```

Relation
--------

[](#relation)

❗**All relations properties should have a `readonly` visibility**❗

### ManyToOne

[](#manytoone)

A `ManyToOne` relation is represented by a property `EntityField`.

To add a `ManyToOne` relation in your entity just add a property like this :

```
#[ARelationField("IdCivility", false)]
readonly EntityField $civility;
```

The attribute `ARelationField()` requires 2 arguments :

- A String : The name of the foreign key in your database.
- A boolean : True if your field allow nullable value, False otherwise.

Then instance your property in the constructor :

```
$this->civility = new EntityField(Civility:class,[$this, 'load']);
```

The constructor of this relation requires 2 arguments :

- The FQCN : The first argument needed is the fully qualified class name of your linked class.
- The loader : The second argument needed is the loader of your entity.
    You can once again disable the lazy loading by giving an empty `Closure`.

### OneToMany

[](#onetomany)

A `OneToMany` relation is represented by a property `RelationOTM`.

```
$this->user = new RelationOTM($this, User::class);
```

The constructor of this relation requires 2 arguments :

- The instance : The first argument is the instance of the class the relation is defined in.
- The FQCN : The second argument needed is the fully qualified class name of your linked class.

### ManyToMany

[](#manytomany)

A `ManyToMany` is represented by a property `RelationMTM`.

```
$this->drivingLicenses = new RelationMTM($this,
                                        DrivingLicense::class,
                                        User_DrivingLicenseRepository::class
                                        );
```

The constructor of this relation requires 3 arguments :

- The instance : The first argument is the instance of the class the relation is defined in.
- The first FQCN : The second argument needed is the fully qualified class name of your linked class.
- The second FQCN : The last argument needed is the fully qualified class name of the repository of the association table.

Inheritance
-----------

[](#inheritance)

To use inheritance, just make your child entity extends another entity.

```
class Consumer extends User
{
    protected static string $entityName = 'Consumer';

    protected static string $repositoryClass = ConsumerRepository::class

    readonly RelationOTM $purchase;

    public function __construct($id = null){
        parent::__construct($id);

        $this->purchase = new RelationOTM($this, Purchase::class);
    }
}
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance79

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

4

Last Release

111d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f81c210b5fdc59ca440634e2bd2afa6df0c696d1a35461fafb4ca4ebeeacc34a?d=identicon)[Fiseo](/maintainers/Fiseo)

---

Top Contributors

[![Fiseo](https://avatars.githubusercontent.com/u/183507713?v=4)](https://github.com/Fiseo "Fiseo (88 commits)")

### Embed Badge

![Health badge](/badges/fiseo-orm-library/health.svg)

```
[![Health](https://phpackages.com/badges/fiseo-orm-library/health.svg)](https://phpackages.com/packages/fiseo-orm-library)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
