承接 tourze/doctrine-hostname-bundle 相关项目开发

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

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

tourze/doctrine-hostname-bundle

Composer 安装命令:

composer require tourze/doctrine-hostname-bundle

包简介

记录Hostname

README 文档

README

English | 中文

Latest Version PHP Version License Build Status Code Coverage Quality Score Total Downloads

A Symfony bundle that automatically records the hostname when creating or updating Doctrine entities. This bundle helps track which server handled entity operations in distributed systems.

Features

  • Automatic hostname recording: Captures server hostname during entity persistence
  • Attribute-based configuration: Uses PHP 8.1 attributes for clean, declarative setup
  • Separate creation and update tracking: Different attributes for creation vs update operations
  • Non-intrusive: Doesn't overwrite existing values if already set
  • Logger integration: Optional debug logging for troubleshooting
  • High performance: Minimal overhead with -99 priority to run after other listeners

Requirements

  • PHP 8.1 or higher
  • Symfony 6.4 or higher
  • Doctrine Bundle 2.13 or higher
  • Doctrine ORM 3.0 or higher

Installation

composer require tourze/doctrine-hostname-bundle

The bundle will be automatically registered in your Symfony application.

Quick Start

Add the attributes to your entity properties:

<?php

use Doctrine\ORM\Mapping as ORM;
use Tourze\DoctrineHostnameBundle\Attribute\CreatedInHostColumn;
use Tourze\DoctrineHostnameBundle\Attribute\UpdatedInHostColumn;

#[ORM\Entity]
class Product
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 255)]
    private ?string $name = null;

    #[CreatedInHostColumn]
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    private ?string $createdInHost = null;

    #[UpdatedInHostColumn]
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    private ?string $updatedInHost = null;

    // Getters and setters...
    public function getCreatedInHost(): ?string
    {
        return $this->createdInHost;
    }

    public function setCreatedInHost(?string $createdInHost): void
    {
        $this->createdInHost = $createdInHost;
    }

    public function getUpdatedInHost(): ?string
    {
        return $this->updatedInHost;
    }

    public function setUpdatedInHost(?string $updatedInHost): void
    {
        $this->updatedInHost = $updatedInHost;
    }
}

How It Works

The bundle automatically:

  1. On entity creation: Sets createdInHost to the current server hostname using PHP's gethostname() function
  2. On entity update: Sets updatedInHost to the current server hostname when entity data changes
  3. Preserves existing values: Won't overwrite hostname if already set (useful for manual assignments)
  4. Logs operations: Provides debug logging for monitoring hostname assignments

Use Cases

  • Distributed systems: Track which server processed specific entities
  • Load balancing: Monitor entity operations across multiple application servers
  • Auditing: Maintain hostname records for compliance and troubleshooting
  • Performance monitoring: Analyze entity operations by server location

Advanced Usage

Custom Property Names

You can use any property name with the attributes:

class MyEntity
{
    #[CreatedInHostColumn]
    private ?string $originServer = null;

    #[UpdatedInHostColumn]
    private ?string $lastModifiedServer = null;
}

Conditional Hostname Setting

The bundle respects existing values:

$entity = new Product();
$entity->setCreatedInHost('manual-override');
$entityManager->persist($entity);
$entityManager->flush();
// createdInHost will remain 'manual-override'

Configuration

The bundle requires no configuration and works out of the box. It automatically registers:

  • HostListener as a Doctrine event subscriber
  • Custom PropertyAccessor service for safe property access
  • Debug logging integration (if logger is available)

Testing

Run the test suite:

./vendor/bin/phpunit packages/doctrine-hostname-bundle/tests

The bundle includes comprehensive unit and integration tests covering:

  • Attribute functionality
  • Event listener behavior
  • Service container integration
  • Hostname recording logic

Performance Considerations

  • Minimal overhead: Uses reflection only during entity operations
  • Efficient execution: Runs with -99 priority to execute after other listeners
  • Memory conscious: Properly handles PropertyAccessor exceptions
  • Change detection: Only updates hostname when entity data actually changes

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Please follow PSR-12 coding standards and include appropriate tests.

License

The MIT License (MIT). Please see License File for more information.

Changelog

See [CHANGELOG.md] for version history and breaking changes (if available).

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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