承接 michel/paper-orm 相关项目开发

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

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

michel/paper-orm

Composer 安装命令:

composer require michel/paper-orm

包简介

PaperORM is a lightweight Object-Relational Mapping (ORM) library

README 文档

README

PaperORM is a PHP ORM designed for projects requiring a lightweight yet performant object-relational mapping solution.

📖 Documentation

English

PaperORM is a PHP ORM designed for projects requiring a lightweight yet performant object-relational mapping solution. Specifically developed for PHP 7.4 and above, it positions itself as a lighter alternative to existing solutions.

At just 5MB compared to Doctrine's 75MB with dependencies, PaperORM offers the essential features of a modern ORM while maintaining a minimal footprint. It includes:

  • Database schema management
  • Migration system
  • Repository pattern

Installation

PaperORM is available via Composer and installs in seconds.

📦 Via Composer (recommended)

composer require michel/paper-orm

🔧 Minimal Configuration

Create a simple configuration file to connect PaperORM to your database:

<?php
require_once 'vendor/autoload.php';

use Michel\PaperORM\EntityManager;
use Michel\PaperORM\PaperConfiguration;

// --- Basic SQLite configuration ---
$configuration = PaperConfiguration::fromArray([
    'driver' => 'sqlite',
    'user' => null,
    'password' => null,
    'memory' => true
], false); // Set to true to enable debug mode (logs queries and ORM operations)

// Basic configuration MySQL/Mariadb
$configuration = PaperConfiguration::fromArray([
            'driver' => 'mariadb',
            'host' => '127.0.0.1',
            'port' => 3306,
            'dbname' => 'paper_orm_test',
            'user' => 'root',
            'password' => 'root',
            'charset' => 'utf8mb4',
], false);  // Set to true to enable debug mode (logs queries and ORM operations)

// --- Optional event listener registration ---
// Called automatically before any entity creation
$configuration->withListener(PreCreateEvent::class, new App\Listener\PreCreateListener());

// --- Optional SQL logger ---
// Use any PSR-3 compatible logger (e.g. Monolog) to log all executed queries
$configuration->withLogger(new Monolog());

$em = EntityManager::createFromConfig($configuration);

PaperORM is now ready to use!

Note: PDO and corresponding database extensions must be enabled (pdo_mysql, pdo_sqlite, etc.).

Basic Usage

Note: The repository attribute/method is optional. If none is defined, a dummy repository will be automatically generated.

Defining an Entity

PHP 7.4 < 8

use Michel\PaperORM\Entity\EntityInterface;
use Michel\PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};

class User implements EntityInterface
{
    private ?int $id = null;
    private string $name;
    private string $email;
    private bool $isActive = true;
    private \DateTime $createdAt;
    
    public static function getTableName(): string 
    {
        return 'users';
    }
    
    public static function columnsMapping(): array
    {
        return [
            (new PrimaryKeyColumn())->bindProperty('id'),
            (new StringColumn())->bindProperty('name'),
            (new StringColumn())->bindProperty('email'),
            (new BoolColumn('is_active'))->bindProperty('isActive'), // 'is_active' is the column name
            (new DateTimeColumn('created_at'))->bindProperty('createdAt') // 'created_at' is the column name
        ];
    }
    
    // Getters/Setters...
}

PHP 8+ with attributes

use Michel\PaperORM\Entity\EntityInterface;
use Michel\PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};

#[Entity(table : 'user', repository : null)]
class User implements EntityInterface
{
    #[PrimaryKeyColumn]
    private ?int $id = null;
    #[StringColumn]
    private string $name;
    #[StringColumn]
    private string $email;
    #[BoolColumn(name: 'is_active')]
    private bool $isActive = true;
    #[DateTimeColumn(name: 'created_at')]
    private \DateTime $createdAt;
   
    
    // Getters/Setters...
}

CRUD Operations

Fetching Entities:

// Get user by ID
$user = $entityManager->getRepository(User::class)->find(1);

// Filtered query
$users = $entityManager->getRepository(User::class)
    ->findBy()
    ->where('isActive', true)
    ->orderBy('name', 'ASC')
    ->limit(10)
    ->toArray();

Insert/Update:

$newUser = new User();
$newUser->setName('Jean Dupont')
        ->setEmail('jean@example.com');

$entityManager->persist($newUser);
$entityManager->flush();

Delete:

$user = $entityManager->getRepository(User::class)->find(1);
$entityManager->remove($user);
$entityManager->flush();

Entity Relationships

// OneToMany relationship
class Article 
{
    // IF PHP >= 8
    #[\Michel\PaperORM\Mapping\OneToMany(Comment::class, 'article')] 
    private \Michel\PaperORM\Collection\ObjectStorage $comments;
    
    public function __construct() {
        $this->comments = new ObjectStorage();
    }
    
    // ...
    public static function columnsMapping(): array
    {
        return [
            new OneToMany('comments', Comment::class, 'article')
        ];
    }
}

// Fetch with join
$articleWithComments = $entityManager->getRepository(Article::class)
    ->find(1)
    ->with('comments')
    ->toObject();

Result Formats

// Associative array
$userArray = $repository->find(1)->toArray();

// Entity object
$userObject = $repository->find(1)->toObject();

// Object collection
$activeUsers = $repository->findBy()
    ->where('isActive', true)
    ->toObject();

PaperORM offers a simple API while covering the essential needs of a modern ORM.

Beta Version - Contribute to Development

PaperORM is currently in beta version and actively evolving. We invite interested developers to:

🐞 Report Bugs

If you encounter issues, open a GitHub issue detailing:

  • Context
  • Reproduction steps
  • Expected vs. actual behavior

💡 Suggest Improvements

Ideas for:

  • Performance optimization
  • API improvements
  • New features

📖 Contribute to Documentation

Complete documentation is being written. You can:

  • Fix errors
  • Add examples
  • Translate sections

Note: This version is stable for development use but requires additional testing for production.

Active development continues - stay tuned for updates!

Français

PaperORM est un ORM PHP conçu pour les projets qui nécessitent une solution de mapping objet-relationnel légère et performante. Développé spécifiquement pour PHP 7.4 et versions ultérieures, il se positionne comme une alternative plus légère aux solutions existantes.

Avec seulement 3Mo contre 75Mo pour Doctrine avec ses dépendances, PaperORM propose les fonctionnalités essentielles d'un ORM moderne tout en conservant une empreinte minimale. Il intègre notamment :

  • La gestion des schémas de base de données
  • Un système de migrations
  • Le pattern Repository

Installation

PaperORM est disponible via Composer et s'installe en quelques secondes.

📦 Via Composer (recommandé)

composer require michel/paper-orm

🔧 Configuration minimale

Créez un fichier de configuration simple pour connecter PaperORM à votre base de données :

<?php
require_once 'vendor/autoload.php';


use Michel\PaperORM\EntityManager;
use Michel\PaperORM\PaperConfiguration;

// --- Basic SQLite configuration ---
$configuration = PaperConfiguration::fromArray([
    'driver' => 'sqlite',
    'user' => null,
    'password' => null,
    'memory' => true
], false); // Mettre à true pour activer le mode debug (journalisation des requêtes et opérations ORM)

// Basic configuration MySQL/Mariadb
$configuration = PaperConfiguration::fromArray([
            'driver' => 'mariadb',
            'host' => '127.0.0.1',
            'port' => 3306,
            'dbname' => 'paper_orm_test',
            'user' => 'root',
            'password' => 'root',
            'charset' => 'utf8mb4',
], false);  // Set to true to enable debug mode (logs queries and ORM operations)

// --- Enregistrement optionnel d’un écouteur d’événement ---
// Appelé automatiquement avant chaque création d’entité
$configuration->withListener(PreCreateEvent::class, new App\Listener\PreCreateListener());

// --- Journalisation SQL optionnelle ---
// Permet de journaliser toutes les requêtes exécutées via un logger compatible PSR-3 (ex. Monolog
$configuration->withLogger(new Monolog());

$em = EntityManager::createFromConfig($configuration);

PaperORM est maintenant prêt à être utilisé !

Remarque : PDO et les extensions correspondantes à votre SGBD doivent être activées (pdo_mysql, pdo_sqlite, etc.).

Utilisation de base

Note: L’attribut ou la méthode repository est facultatif. Si aucun n’est défini, un repository fictif sera généré automatiquement.

Définition d'une entité

PHP 7.4 < 8

use Michel\PaperORM\Entity\EntityInterface;
use Michel\PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};

class User implements EntityInterface
{
    private ?int $id = null;
    private string $name;
    private string $email;
    private bool $isActive = true;
    private \DateTime $createdAt;
    
    public static function getTableName(): string 
    {
        return 'users';
    }
    
    public static function columnsMapping(): array
    {
        return [
            new PrimaryKeyColumn('id'),
            new StringColumn('name'),
            new StringColumn('email'),
            new BoolColumn('isActive'),
            new DateTimeColumn('createdAt')
        ];
    }
    
    // Getters/Setters...
}

PHP 8+ avec attributs

use Michel\PaperORM\Entity\EntityInterface;
use Michel\PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};

#[Entity(table : 'user', repository : null)]
class User implements EntityInterface
{
    #[PrimaryKeyColumn]
    private ?int $id = null;
    #[StringColumn]
    private string $name;
    #[StringColumn]
    private string $email;
    #[BoolColumn(name: 'is_active')]
    private bool $isActive = true;
    #[DateTimeColumn(name: 'created_at')]
    private \DateTime $createdAt;
   
    
    // Getters/Setters...
}

Opérations CRUD

Récupération d'entités :

// Récupérer un utilisateur par ID
$user = $entityManager->getRepository(User::class)->find(1);

// Requête avec filtres
$users = $entityManager->getRepository(User::class)
    ->findBy()
    ->where('isActive', true)
    ->orderBy('name', 'ASC')
    ->limit(10)
    ->toArray();

Insertion/Mise à jour :

$newUser = new User();
$newUser->setName('Jean Dupont')
        ->setEmail('jean@example.com');

$entityManager->persist($newUser);
$entityManager->flush();

Suppression :

$user = $entityManager->getRepository(User::class)->find(1);
$entityManager->remove($user);
$entityManager->flush();

Relations entre entités

// Relation OneToMany
class Article 
{
    // IF PHP >= 8
    #[\Michel\PaperORM\Mapping\OneToMany(Comment::class, 'article')] 
    private \Michel\PaperORM\Collection\ObjectStorage $comments;
    
    public function __construct() {
        $this->comments = new ObjectStorage();
    }
    
    // ...
    public static function columnsMapping(): array
    {
        return [
            new OneToMany('comments', Comment::class, 'article')
        ];
    }
}

// Récupération avec jointure
$articleWithComments = $entityManager->getRepository(Article::class)
    ->find(1)
    ->with('comments')
    ->toObject();

Format des résultats

// Tableau associatif
$userArray = $repository->find(1)->toArray();

// Objet entité
$userObject = $repository->find(1)->toObject();

// Collection d'objets
$activeUsers = $repository->findBy()
    ->where('isActive', true)
    ->toCollection();

PaperORM propose une API simple tout en couvrant les besoins essentiels d'un ORM moderne.

Version Bêta - Contribuez au développement

PaperORM est actuellement en version bêta et évolue activement. Nous invitons tous les développeurs intéressés à :

🐞 Signaler des bugs

Si vous rencontrez un problème, ouvrez une issue GitHub en détaillant :

  • Le contexte
  • Les étapes pour reproduire
  • Le comportement attendu vs. observé

💡 Proposer des améliorations

Des idées pour :

  • Optimiser les performances
  • Améliorer l'API
  • Ajouter des fonctionnalités

📖 Contribuer à la documentation

La documentation complète est en cours de rédaction. Vous pouvez :

  • Corriger des erreurs
  • Ajouter des exemples
  • Traduire des sections

Note : Cette version est stable pour un usage en développement, mais nécessite des tests supplémentaires pour la production.

Le développement actif continue - restez à l'écoute pour les mises à jour !

michel/paper-orm 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2025-12-16