承接 fiseo/orm-library 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fiseo/orm-library

Composer 安装命令:

composer require 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)

README 文档

README

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

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❗

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

Quick start

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 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 for each of your tables by extending the abstract class AbstractEntity
To add a field, create a readonly property of a field class 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

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

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

All relations properties should have a readonly visibility

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

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

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

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);
    }
}

fiseo/orm-library 适用场景与选型建议

fiseo/orm-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 fiseo/orm-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fiseo/orm-library 我们能提供哪些服务?
定制开发 / 二次开发

基于 fiseo/orm-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-09