承接 gcworld/objectmanager 相关项目开发

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

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

gcworld/objectmanager

Composer 安装命令:

composer require gcworld/objectmanager

包简介

GCWorld Industries Object Manager

README 文档

README

A simple object manager that maintains objects in memory

Version

2.9.2

ObjectManager Attributes

Use PHP attributes instead of docblocks to mark classes for manager generation.

Class Attribute

use GCWorld\ObjectManager\Attributes\ObjectManagerAttribute;
use GCWorld\ObjectManager\Enums\ObjectManagerMethod;

#[ObjectManagerAttribute(method: ObjectManagerMethod::GetObject, gc: 100)]
class User
{
}

Available ObjectManagerAttribute arguments:

Argument Required Notes
method yes ObjectManagerMethod::GetObject, ::GetModel, ::GetFactoryObject, ::GetFactoryModelObject
name no Getter suffix override. Defaults to the class short name.
namespace no Namespace override used in generated manager methods.
gc no Automated garbage-collection limit. 0 disables it.

These enum cases map to the generated manager behaviors getObject, getModel, getFactoryObject, and getFactoryModelObject.

Factory Methods

Factory-backed classes use a class attribute plus one or more attributed public static methods.

use GCWorld\ObjectManager\Attributes\ObjectFactoryAttribute;
use GCWorld\ObjectManager\Attributes\ObjectManagerAttribute;
use GCWorld\ObjectManager\Enums\ObjectManagerMethod;

#[ObjectManagerAttribute(method: ObjectManagerMethod::GetFactoryObject)]
class User
{
    public const CLASS_PRIMARY = 'uuid';

    #[ObjectFactoryAttribute]
    public static function factoryByUuid(string $uuid): self
    {
        // ...
    }

    #[ObjectFactoryAttribute]
    public static function factoryLookup(string $email, string $name): self
    {
        // ...
    }
}

The generator reflects the attributed static method parameters directly. There is no separate attribute syntax for ordered factory args.

Generating The Manager

Generate the manager after your models are autoloadable and your scan path has been added:

use GCWorld\ObjectManager\Generator;

$generator = new Generator();
$generator->addPath(__DIR__.'/src/Model');
$generator->generate();

This writes the generated manager class to src/Generated/GeneratedManager.php.

Testing

The repository includes a PHPUnit suite that exercises the generator against fixture models.

composer test

Current coverage is focused on:

  • basic attributed object getter generation
  • factory wrapper generation from attributed static methods
  • getFactoryModelObject wrapper generation
  • invalid #[ObjectFactoryAttribute] usage on non-public or non-static methods

The tests generate a temporary manager file under src/Generated/ during execution and clean it up afterward.

Migrating Legacy @om-* Docblocks

Legacy class docblocks can be converted to attributes with the bundled migration script.

Dry run:

composer migrate-docblocks -- --dry-run path/to/src

Apply changes:

composer migrate-docblocks -- path/to/src

What the migrator does:

  • converts class-level @om-method, @om-name, @om-namespace, and @om-gc tags into #[ObjectManagerAttribute(...)] using ObjectManagerMethod
  • converts each @om-factory-X-method entry into #[ObjectFactoryAttribute] on the matching class method
  • removes legacy @om-* lines from the class docblock while preserving unrelated docblock text
  • adds the required use GCWorld\ObjectManager\Attributes\ObjectManagerAttribute;, use GCWorld\ObjectManager\Attributes\ObjectFactoryAttribute;, and use GCWorld\ObjectManager\Enums\ObjectManagerMethod; imports

The script only migrates factory metadata when every referenced legacy factory method can be resolved in the class. If a declared factory method is missing, the file is skipped and a warning is reported so existing metadata is not destroyed.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固