unapartidamas/weaver-orm 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

unapartidamas/weaver-orm

最新稳定版本:1.2.0

Composer 安装命令:

composer require unapartidamas/weaver-orm

包简介

PHP 8.4+ ORM for Symfony. Zero reflection, no proxies, no memory leaks. Worker-safe by design.

README 文档

README

A modern, high-performance ORM for PHP 8.4+. Zero reflection, no proxy classes, no memory leaks, no Doctrine dependency. Worker-safe by design.

Compatible with Symfony, Laravel, and CodeIgniter 4.

Benchmarks

Weaver ORM vs Doctrine ORM vs Eloquent (SQLite in-memory, 2000 iterations, PHP 8.4):

Operation Weaver ORM Doctrine ORM Eloquent Winner
Single INSERT 0.069ms 0.143ms 0.352ms Weaver 2.1x
Batch INSERT (100 rows) 2.89ms 7.57ms 27.74ms Weaver 2.6x
SELECT by PK 0.068ms 0.090ms 0.245ms Weaver 1.3x
Complex SELECT 0.216ms 0.595ms 0.519ms Weaver 2.8x
UPDATE 0.061ms 0.091ms 0.266ms Weaver 1.5x
Hydration (100 rows) 0.834ms 2.148ms 2.448ms Weaver 2.6x

Weaver wins 6/6 benchmarks. Run php benchmark/run-orm-comparison.php to reproduce.

Why Weaver?

Doctrine ORM Eloquent Weaver ORM
Dependencies doctrine/dbal, doctrine/common, ... illuminate/database, ... ext-pdo only
PHP version 8.1+ 8.2+ 8.4+
Proxy classes Generated, reflection-heavy N/A (ActiveRecord) None (PHP 8.4 property hooks)
Memory Identity map grows unbounded Model instances per query Worker-safe, request-scoped
Query language DQL Eloquent Builder Plain SQL query builder
PyroSQL Not supported Not supported Native (time travel, vectors, CDC)

Requirements

  • PHP 8.4+
  • ext-pdo (+ driver: pdo_pgsql, pdo_mysql, or pdo_sqlite)

Zero framework dependencies. No Doctrine, no Symfony, no Laravel in the core.

Installation

composer require unapartidamas/weaver-orm

Symfony

// config/bundles.php
return [
    Weaver\ORM\Bridge\Symfony\WeaverBundle::class => ['all' => true],
];

Laravel

// config/app.php (or auto-discovered)
'providers' => [
    Weaver\ORM\Bridge\Laravel\WeaverServiceProvider::class,
],

CodeIgniter 4

// Use the service locator
$workspace = \Weaver\ORM\Bridge\CodeIgniter\WeaverService::workspace();

Quick Start

use Weaver\ORM\Mapping\Attribute\{Entity, Id, Column, Timestamps};

#[Entity(table: 'users')]
#[Timestamps]
class User
{
    #[Id]
    public ?int $id = null;

    #[Column]
    public string $name;

    #[Column]
    public string $email;
}
$workspace->add($user);
$workspace->push();

$users = $repo->query()
    ->where('name', 'LIKE', '%ali%')
    ->orderBy('created_at', 'DESC')
    ->limit(10)
    ->get();

$workspace->delete($user);
$workspace->push();

Configuration

# config/packages/weaver.yaml
weaver:
    connections:
        default:
            driver: pdo_pgsql  # pdo_mysql, pdo_sqlite, pyrosql
            url: '%env(DATABASE_URL)%'
    default_connection: default
    debug: '%kernel.debug%'
    n1_detector: '%kernel.debug%'

API

Doctrine Weaver Description
persist() add() Track a new entity
flush() push() Write all changes to DB
remove() delete() Mark for deletion
detach() untrack() Stop tracking entity
contains() isTracked() Check if managed
refresh() reload() Re-read from DB
clear() reset() Clear tracked entities
EntityManager EntityWorkspace Main entry point

Features

Core - Entity mapping with attributes, HasOne/HasMany/BelongsTo/BelongsToMany/MorphOne/MorphMany relations, identity map, change tracking, lazy loading (PHP 8.4 hooks), optimistic + pessimistic locking, nested embeddables, single-table + joined-table inheritance, batch operations, criteria pattern.

Query Builder - Fluent API, global/local scopes, runtime filter toggle, eager loading, cursor + offset pagination, query result caching.

Caching - Second Level Cache (PSR-16), query result cache, per-entity cache regions.

Multi-Database - Named connections, #[Connection('analytics')] per entity, WorkspaceRegistry, read/write splitting.

Schema - Generation from mappers, diff, validation. Commands: schema:create, schema:update, schema:drop, schema:diff.

Events - Lifecycle hooks (#[BeforeAdd], #[AfterAdd], etc.), priorities, Symfony/Laravel/CI4 dispatcher integration.

Testing - EntityFactory, DatabaseTransactions trait, RefreshDatabase trait, SQLite in-memory.

Profiling - Query profiler, N+1 detection, Symfony Web Debug Toolbar.

PyroSQL - Time travel (AS OF), branching, CDC, approximate queries, vector search, WASM UDFs, native syntax (FIND, ADD, CHANGE, REMOVE, SEARCH, NEAREST).

Migrating from Doctrine

use Weaver\ORM\Bridge\Doctrine\DoctrineCompatEntityManager;

$em = new DoctrineCompatEntityManager($workspace);
$em->persist($entity);  // calls $workspace->add()
$em->flush();            // calls $workspace->push()

Documentation

unapartidamas.github.io/weaverORM

License

MIT

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固