tourze/doctrine-user-bundle 问题修复 & 功能扩展

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

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

tourze/doctrine-user-bundle

Composer 安装命令:

composer require tourze/doctrine-user-bundle

包简介

A Symfony Bundle for automatically tracking entity creators and updaters

README 文档

README

English | 中文

Latest Version Total Downloads PHP Version Require Code Coverage License

A Symfony Bundle for automatically tracking entity creators and updaters.

Features

  • Automatically track entity creators and updaters
  • Simple integration using PHP 8 Attributes
  • Works with Symfony Security component
  • No database schema modifications required
  • Compatible with Symfony 7.3+ applications
  • Zero configuration required

Installation

Install this package via Composer:

composer require tourze/doctrine-user-bundle

Requirements

  • PHP 8.1+
  • Symfony 7.3+
  • Doctrine ORM

Usage

Basic Usage

In your entity classes, use the CreateUserColumn and UpdateUserColumn attributes to mark user fields:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Tourze\DoctrineUserBundle\Attribute\CreateUserColumn;
use Tourze\DoctrineUserBundle\Attribute\UpdateUserColumn;

#[ORM\Entity]
class YourEntity
{
    // ...

    #[ORM\ManyToOne(targetEntity: User::class)]
    #[CreateUserColumn]
    private ?UserInterface $createdBy = null;

    #[ORM\ManyToOne(targetEntity: User::class)]
    #[UpdateUserColumn]
    private ?UserInterface $updatedBy = null;

    // ...

    public function getCreatedBy(): ?UserInterface
    {
        return $this->createdBy;
    }

    public function getUpdatedBy(): ?UserInterface
    {
        return $this->updatedBy;
    }
}

When an entity is created or updated, the marked fields will automatically be set to the currently logged-in user.

Alternative Attributes

The bundle also provides additional attributes for more specific use cases:

  • CreatedByColumn: Records only the essential information about the creator
  • UpdatedByColumn: Records only the essential information about the updater

Configuration

In your Symfony project, ensure the bundle is registered in the config/bundles.php file:

return [
    // ...
    Tourze\DoctrineUserBundle\DoctrineUserBundle::class => ['all' => true],
];

The bundle will be automatically configured with sensible defaults.

Advanced Usage

Custom Property Accessor

If you need to customize how properties are accessed, you can override the property accessor service:

# config/services.yaml
services:
    doctrine-user.property-accessor:
        class: Symfony\Component\PropertyAccess\PropertyAccessor
        arguments:
            - false  # magicCall
            - false  # throwExceptionOnInvalidIndex
            - 1      # cacheItemLifetime
            - false  # magicSet
            - false  # magicGet

Logging Configuration

The bundle uses Monolog for logging. You can configure the logger channel:

# config/packages/monolog.yaml
monolog:
    channels: ['doctrine_user']
    handlers:
        doctrine_user:
            type: stream
            path: '%kernel.logs_dir%/doctrine_user.log'
            level: debug
            channels: ['doctrine_user']

Entity Checker Integration

This bundle integrates with the doctrine-entity-checker-bundle to provide additional validation capabilities.

How It Works

This bundle leverages Doctrine's event system to automatically set the user fields when entities are persisted or updated. The UserListener class subscribes to Doctrine's prePersist and preUpdate events and sets the appropriate user fields based on the current security context.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

tourze/doctrine-user-bundle 适用场景与选型建议

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

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

围绕 tourze/doctrine-user-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-27