PHPackages                             tourze/user-attribute-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tourze/user-attribute-bundle

ActiveLibrary

tourze/user-attribute-bundle
============================

用户属性管理 Bundle，提供用户自定义属性的存储和管理功能

1.0.1(6mo ago)0371MITPHPCI passing

Since Nov 5Pushed 5mo agoCompare

[ Source](https://github.com/tourze/user-attribute-bundle)[ Packagist](https://packagist.org/packages/tourze/user-attribute-bundle)[ RSS](/packages/tourze-user-attribute-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (38)Versions (3)Used By (1)

User Attribute Bundle
=====================

[](#user-attribute-bundle)

[![PHP Version](https://camo.githubusercontent.com/a99b89ee7573ef29b89ce4492fe05ec3aa31798b9e9257dff2a7bc6139e1a572/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e342d373837434235)](https://php.net)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)[![Build Status](https://camo.githubusercontent.com/b0c6c6845a74cb65a7f0a32bdcfd8fbf80eeb40026c4029af424ab371c94b8bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e)](https://github.com/tourze/php-monorepo)[![Code Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](https://github.com/tourze/php-monorepo)

[English](README.md) | [中文](README.zh-CN.md)

A Symfony bundle for managing user attributes with key-value storage, IP tracking, and admin interface integration.

Features
--------

[](#features)

- Key-value storage for user attributes
- User-specific attribute management
- IP tracking for operations
- Snowflake ID generation
- Admin menu integration
- REST API support
- Doctrine ORM integration

Installation
------------

[](#installation)

```
composer require tourze/user-attribute-bundle
```

Quick Start
-----------

[](#quick-start)

1. Add the bundle to your `config/bundles.php`:

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

2. Run migrations to create the database table:

```
php bin/console doctrine:migrations:migrate
```

3. The bundle will automatically register services and admin menu items.

Configuration
-------------

[](#configuration)

The bundle uses default configuration with the following features:

- **Entity**: `UserAttribute` with IP tracking, timestamps, and blame tracking
- **Repository**: `UserAttributeRepository` for data operations
- **Admin Menu**: Automatic integration with EasyAdmin menu system
- **Database Table**: `biz_user_attribute` with unique constraint on `user_id` and `name`

Usage
-----

[](#usage)

### Working with User Attributes

[](#working-with-user-attributes)

```
use Tourze\UserAttributeBundle\Entity\UserAttribute;
use Tourze\UserAttributeBundle\Repository\UserAttributeRepository;

// Create a new user attribute
$attribute = new UserAttribute();
$attribute->setUser($user);
$attribute->setName('preferred_language');
$attribute->setValue('en');
$attribute->setRemark('User preference for language');

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

// Retrieve user attributes
$repository = $entityManager->getRepository(UserAttribute::class);
$attributes = $repository->findBy(['user' => $user]);
```

### REST API Integration

[](#rest-api-integration)

The entity supports REST API serialization with groups:

```
// API response format
$apiData = $attribute->retrieveApiArray();
// Returns: ['id' => 123, 'name' => 'preferred_language', 'value' => 'en']

// Admin interface format
$adminData = $attribute->retrieveAdminArray();
// Returns: ['id' => 123, 'name' => 'preferred_language', 'value' => 'en', 'remark' => 'User preference']
```

### Admin Menu Integration

[](#admin-menu-integration)

The bundle automatically adds a "User Attribute Management" menu item under "User Module" in the admin interface.

Advanced Usage
--------------

[](#advanced-usage)

### Custom Repository Methods

[](#custom-repository-methods)

You can extend the repository to add custom query methods:

```
// In your application
class CustomUserAttributeRepository extends UserAttributeRepository
{
    public function findAttributesByPrefix(UserInterface $user, string $prefix): array
    {
        return $this->createQueryBuilder('ua')
            ->where('ua.user = :user')
            ->andWhere('ua.name LIKE :prefix')
            ->setParameter('user', $user)
            ->setParameter('prefix', $prefix . '%')
            ->getQuery()
            ->getResult();
    }
}
```

### Bulk Operations

[](#bulk-operations)

For performance-critical operations, consider bulk updates:

```
// Bulk update user attributes
$qb = $entityManager->createQueryBuilder()
    ->update(UserAttribute::class, 'ua')
    ->set('ua.value', ':newValue')
    ->where('ua.user = :user')
    ->andWhere('ua.name = :name')
    ->setParameter('newValue', $newValue)
    ->setParameter('user', $user)
    ->setParameter('name', $attributeName);

$qb->getQuery()->execute();
```

### Event Handling

[](#event-handling)

You can listen to Doctrine events for custom logic:

```
use Doctrine\ORM\Events;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;

#[AsDoctrineListener(event: Events::prePersist)]
class UserAttributeListener
{
    public function prePersist(UserAttribute $attribute): void
    {
        // Custom logic before saving
        if ($attribute->getName() === 'sensitive_data') {
            $attribute->setValue(hash('sha256', $attribute->getValue()));
        }
    }
}
```

Dependencies
------------

[](#dependencies)

- PHP 8.4+
- Symfony 7.3+
- Doctrine ORM 3.0+
- KnpMenu 3.7+
- EasyAdmin 4.0+
- Various tourze/\* packages for extended functionality

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this project.

License
-------

[](#license)

This bundle is released under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance71

Regular maintenance activity

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

2

Last Release

186d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-user-attribute-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-user-attribute-bundle/health.svg)](https://phpackages.com/packages/tourze-user-attribute-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
