PHPackages                             tourze/doctrine-user-agent-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/doctrine-user-agent-bundle

ActiveLibrary

tourze/doctrine-user-agent-bundle
=================================

A Symfony bundle that automatically captures and records User-Agent information in Doctrine entities for analytics and audit purposes

1.0.0(6mo ago)016.0k4MITPHPCI passing

Since Apr 7Pushed 4mo ago1 watchersCompare

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

READMEChangelog (6)Dependencies (22)Versions (7)Used By (4)

Doctrine User Agent Bundle
==========================

[](#doctrine-user-agent-bundle)

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

[![Latest Version](https://camo.githubusercontent.com/a57ab94704026bf15c3c79d6bea588d84ec2c70e1a44b98823bf6a785aa6f648/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f646f637472696e652d757365722d6167656e742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-user-agent-bundle)[![Total Downloads](https://camo.githubusercontent.com/13d26a18ecf9130d5275b1b38ba5c612dfbeb24af8c019ee9151539c8223e0ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f646f637472696e652d757365722d6167656e742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-user-agent-bundle)[![PHP Version Require](https://camo.githubusercontent.com/35589cd9cb6f30db2c1d863922274b1c379d101041a018149f44317fa0af80cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f746f75727a652f646f637472696e652d757365722d6167656e742d62756e646c652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-user-agent-bundle)[![License](https://camo.githubusercontent.com/4d4f48bf0534cfaf93bf44602a02a8b2d98a7cce6a8da78822738d5bc50f5463/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f646f637472696e652d757365722d6167656e742d62756e646c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-user-agent-bundle)[![Code Coverage](https://camo.githubusercontent.com/a0bb748c2a297320a0fa8e7b18ca82fc41094c66d51717a0c5f5ff87fd10aac1/68747470733a2f2f636f6465636f762e696f2f67682f746f75727a652f646f637472696e652d757365722d6167656e742d62756e646c652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/tourze/doctrine-user-agent-bundle)

A Symfony bundle that automatically captures and records User-Agent information in Doctrine entities for analytics and audit purposes.

Features
--------

[](#features)

- 🚀 **Zero Configuration** - Works out of the box with simple attributes
- 📱 **Auto-Detection** - Automatically captures User-Agent from HTTP requests
- 🏷️ **Attribute-Based** - Simple PHP 8+ attributes to mark entity properties
- ⚡ **Event-Driven** - Seamless integration with Doctrine ORM lifecycle events
- 🔄 **Create &amp; Update** - Separate tracking for entity creation and modification
- 🧩 **Ready-to-Use Traits** - Pre-built traits for common use cases
- 🔒 **Non-Intrusive** - Only sets values when properties are null

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

[](#installation)

```
composer require tourze/doctrine-user-agent-bundle
```

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

[](#quick-start)

1. Add the bundle to your application's kernel:

```
// config/bundles.php
return [
    // ...
    Tourze\DoctrineUserAgentBundle\DoctrineUserAgentBundle::class => ['all' => true],
];
```

2. Use attributes in your entity:

```
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Tourze\DoctrineUserAgentBundle\Attribute\CreateUserAgentColumn;
use Tourze\DoctrineUserAgentBundle\Attribute\UpdateUserAgentColumn;

#[ORM\Entity]
class Article
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[CreateUserAgentColumn]
    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $createdUserAgent = null;

    #[UpdateUserAgentColumn]
    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $updatedUserAgent = null;

    // Getters and setters...
}
```

3. Or use the convenience trait:

```
use Tourze\DoctrineUserAgentBundle\Traits\CreatedByUAAware;

#[ORM\Entity]
class Article
{
    use CreatedByUAAware;

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    // Your other properties...
}
```

Usage
-----

[](#usage)

### Available Attributes

[](#available-attributes)

#### `#[CreateUserAgentColumn]`

[](#createuseragentcolumn)

Records the User-Agent header when the entity is first persisted to the database.

```
#[CreateUserAgentColumn]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $createdUserAgent = null;
```

#### `#[UpdateUserAgentColumn]`

[](#updateuseragentcolumn)

Records the User-Agent header when the entity is updated.

```
#[UpdateUserAgentColumn]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $updatedUserAgent = null;
```

### Available Traits

[](#available-traits)

#### `CreatedByUAAware`

[](#createdbyuaaware)

A ready-to-use trait that adds a `createdFromUa` property with proper Doctrine mapping:

```
use Tourze\DoctrineUserAgentBundle\Traits\CreatedByUAAware;

class MyEntity
{
    use CreatedByUAAware;

    // Access the User-Agent
    public function getCreatedFromUa(): ?string
    {
        return $this->createdFromUa;
    }
}
```

### How It Works

[](#how-it-works)

1. **Request Capture**: The bundle listens to Symfony's `KernelEvents::REQUEST` and captures the `User-Agent` header
2. **Entity Events**: When Doctrine triggers `prePersist` or `preUpdate` events, the bundle checks for marked properties
3. **Value Assignment**: Only assigns User-Agent values to properties that are currently `null`
4. **Non-Intrusive**: Existing values are never overwritten

### Use Cases

[](#use-cases)

- **Analytics**: Track which browsers/devices are creating content
- **Audit Logging**: Maintain detailed records of entity modifications
- **Security**: Monitor suspicious User-Agent patterns
- **User Experience**: Understand your users' technology preferences

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- Doctrine DBAL 4.0 or higher
- Doctrine Bundle 2.13 or higher

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

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance71

Regular maintenance activity

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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 ~41 days

Recently: every ~47 days

Total

6

Last Release

191d ago

Major Versions

0.0.5 → 1.0.02025-10-31

### 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 (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/tourze-doctrine-user-agent-bundle/health.svg)](https://phpackages.com/packages/tourze-doctrine-user-agent-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)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)

PHPackages © 2026

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